comparison OrthancServer/LuaScripting.cpp @ 1440:3567503c00a7

lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 10:18:26 +0200
parents 02f5a3f5c0a0
children f3672356c121
comparison
equal deleted inserted replaced
1439:354640db5a7f 1440:3567503c00a7
56 const void* value = LuaContext::GetGlobalVariable(state, "_RestApi"); 56 const void* value = LuaContext::GetGlobalVariable(state, "_RestApi");
57 return const_cast<OrthancRestApi*>(reinterpret_cast<const OrthancRestApi*>(value)); 57 return const_cast<OrthancRestApi*>(reinterpret_cast<const OrthancRestApi*>(value));
58 } 58 }
59 59
60 60
61 int LuaScripting::RestApiGet(lua_State *state) 61 int LuaScripting::OrthancApiGet(lua_State *state)
62 { 62 {
63 OrthancRestApi* restApi = GetRestApi(state); 63 OrthancRestApi* restApi = GetRestApi(state);
64 if (restApi == NULL) 64 if (restApi == NULL)
65 { 65 {
66 LOG(ERROR) << "Lua: The REST API is unavailable"; 66 LOG(ERROR) << "Lua: The Orthanc API is unavailable";
67 lua_pushnil(state); 67 lua_pushnil(state);
68 return 1; 68 return 1;
69 } 69 }
70 70
71 // Check the types of the arguments 71 // Check the types of the arguments
72 int nArgs = lua_gettop(state); 72 int nArgs = lua_gettop(state);
73 if (nArgs != 1 || !lua_isstring(state, 1)) // URI 73 if (nArgs != 1 || !lua_isstring(state, 1)) // URI
74 { 74 {
75 LOG(ERROR) << "Lua: Bad parameters to RestApiGet()"; 75 LOG(ERROR) << "Lua: Bad parameters to OrthancApiGet()";
76 lua_pushnil(state); 76 lua_pushnil(state);
77 return 1; 77 return 1;
78 } 78 }
79 79
80 const char* uri = lua_tostring(state, 1); 80 const char* uri = lua_tostring(state, 1);
84 { 84 {
85 lua_pushstring(state, str.c_str()); 85 lua_pushstring(state, str.c_str());
86 } 86 }
87 else 87 else
88 { 88 {
89 LOG(ERROR) << "Lua: Error in RestApiGet() for URI " << uri; 89 LOG(ERROR) << "Lua: Error in OrthancApiGet() for URI " << uri;
90 lua_pushnil(state); 90 lua_pushnil(state);
91 } 91 }
92 92
93 return 1; 93 return 1;
94 } 94 }
244 } 244 }
245 245
246 246
247 LuaScripting::LuaScripting(ServerContext& context) : context_(context), restApi_(NULL) 247 LuaScripting::LuaScripting(ServerContext& context) : context_(context), restApi_(NULL)
248 { 248 {
249 lua_.RegisterFunction("RestApiGet", RestApiGet); 249 lua_.RegisterFunction("OrthancApiGet", OrthancApiGet);
250 250
251 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX); 251 lua_.Execute(Orthanc::EmbeddedResources::LUA_TOOLBOX);
252 lua_.SetHttpProxy(Configuration::GetGlobalStringParameter("HttpProxy", "")); 252 lua_.SetHttpProxy(Configuration::GetGlobalStringParameter("HttpProxy", ""));
253 } 253 }
254 254