Mercurial > hg > orthanc
comparison UnitTests/Lua.cpp @ 386:7dec4f3c922c lua-scripting
lua wrapper
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 29 Apr 2013 17:14:10 +0200 |
parents | |
children | 941ea46e9e26 |
comparison
equal
deleted
inserted
replaced
384:18fe778eeb95 | 386:7dec4f3c922c |
---|---|
1 #include "gtest/gtest.h" | |
2 | |
3 #include "../Core/Lua/LuaFunctionCall.h" | |
4 | |
5 | |
6 TEST(Lua, Simple) | |
7 { | |
8 try | |
9 { | |
10 Orthanc::LuaContext lua; | |
11 lua.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); | |
12 lua.Execute("a={}"); | |
13 lua.Execute("a['x'] = 10"); | |
14 lua.Execute("a['y'] = {}"); | |
15 lua.Execute("a['y'][1] = 20"); | |
16 lua.Execute("a['y'][2] = 20"); | |
17 lua.Execute("rPrint(a)"); | |
18 | |
19 lua.Execute("function f(a) print(a.bool) return a.bool,20,30,40,50,60 end"); | |
20 | |
21 Json::Value v, vv, o; | |
22 //v["a"] = "b"; | |
23 v.append("hello"); | |
24 v.append("world"); | |
25 v.append("42"); | |
26 vv.append("coucou"); | |
27 vv.append("toi"); | |
28 v.append(vv); | |
29 o = Json::objectValue; | |
30 o["x"] = 10; | |
31 o["y"] = 20; | |
32 o["z"] = 20.5f; | |
33 v.append(o); | |
34 | |
35 { | |
36 Orthanc::LuaFunctionCall f(lua, "rPrint"); | |
37 f.PushJSON(v); | |
38 f.Execute(); | |
39 } | |
40 | |
41 { | |
42 Orthanc::LuaFunctionCall f(lua, "f"); | |
43 f.PushJSON(o); | |
44 ASSERT_THROW(f.ExecutePredicate(), Orthanc::LuaException); | |
45 } | |
46 | |
47 o["bool"] = false; | |
48 | |
49 { | |
50 Orthanc::LuaFunctionCall f(lua, "f"); | |
51 f.PushJSON(o); | |
52 ASSERT_FALSE(f.ExecutePredicate()); | |
53 } | |
54 | |
55 o["bool"] = true; | |
56 | |
57 { | |
58 Orthanc::LuaFunctionCall f(lua, "f"); | |
59 f.PushJSON(o); | |
60 ASSERT_TRUE(f.ExecutePredicate()); | |
61 } | |
62 | |
63 } | |
64 catch (Orthanc::LuaException e) | |
65 { | |
66 std::cerr << "EXCEPTION: [" << e.What() << "]" << std::endl; | |
67 } | |
68 } |