Mercurial > hg > orthanc
comparison Core/Lua/LuaFunctionCall.cpp @ 1051:92f4bf2c5d73
HTTP GET in Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Jul 2014 12:59:28 +0200 |
parents | 160dfe770618 |
children | 6e7e5ed91c2d |
comparison
equal
deleted
inserted
replaced
1050:64f1842aae2e | 1051:92f4bf2c5d73 |
---|---|
83 } | 83 } |
84 | 84 |
85 void LuaFunctionCall::PushJson(const Json::Value& value) | 85 void LuaFunctionCall::PushJson(const Json::Value& value) |
86 { | 86 { |
87 CheckAlreadyExecuted(); | 87 CheckAlreadyExecuted(); |
88 | 88 context_.PushJson(value); |
89 if (value.isString()) | |
90 { | |
91 lua_pushstring(context_.lua_, value.asCString()); | |
92 } | |
93 else if (value.isDouble()) | |
94 { | |
95 lua_pushnumber(context_.lua_, value.asDouble()); | |
96 } | |
97 else if (value.isInt()) | |
98 { | |
99 lua_pushinteger(context_.lua_, value.asInt()); | |
100 } | |
101 else if (value.isUInt()) | |
102 { | |
103 lua_pushinteger(context_.lua_, value.asUInt()); | |
104 } | |
105 else if (value.isBool()) | |
106 { | |
107 lua_pushboolean(context_.lua_, value.asBool()); | |
108 } | |
109 else if (value.isNull()) | |
110 { | |
111 lua_pushnil(context_.lua_); | |
112 } | |
113 else if (value.isArray()) | |
114 { | |
115 lua_newtable(context_.lua_); | |
116 | |
117 // http://lua-users.org/wiki/SimpleLuaApiExample | |
118 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++) | |
119 { | |
120 // Push the table index (note the "+1" because of Lua conventions) | |
121 lua_pushnumber(context_.lua_, i + 1); | |
122 | |
123 // Push the value of the cell | |
124 PushJson(value[i]); | |
125 | |
126 // Stores the pair in the table | |
127 lua_rawset(context_.lua_, -3); | |
128 } | |
129 } | |
130 else if (value.isObject()) | |
131 { | |
132 lua_newtable(context_.lua_); | |
133 | |
134 Json::Value::Members members = value.getMemberNames(); | |
135 | |
136 for (Json::Value::Members::const_iterator | |
137 it = members.begin(); it != members.end(); ++it) | |
138 { | |
139 // Push the index of the cell | |
140 lua_pushstring(context_.lua_, it->c_str()); | |
141 | |
142 // Push the value of the cell | |
143 PushJson(value[*it]); | |
144 | |
145 // Stores the pair in the table | |
146 lua_rawset(context_.lua_, -3); | |
147 } | |
148 } | |
149 else | |
150 { | |
151 throw LuaException("Unsupported JSON conversion"); | |
152 } | |
153 } | 89 } |
154 | 90 |
155 void LuaFunctionCall::ExecuteInternal(int numOutputs) | 91 void LuaFunctionCall::ExecuteInternal(int numOutputs) |
156 { | 92 { |
157 CheckAlreadyExecuted(); | 93 CheckAlreadyExecuted(); |