comparison Core/Lua/LuaContext.cpp @ 1465:905842836ad4

sample Lua script to write DICOM series to disk
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 27 Jul 2015 17:33:47 +0200
parents 3f7722179467
children f967bdf8534e
comparison
equal deleted inserted replaced
1464:f401dd90b35e 1465:905842836ad4
135 Json::Value json; 135 Json::Value json;
136 that.GetJson(json, 1); 136 that.GetJson(json, 1);
137 137
138 Json::FastWriter writer; 138 Json::FastWriter writer;
139 std::string s = writer.write(json); 139 std::string s = writer.write(json);
140 lua_pushstring(state, s.c_str()); 140 lua_pushlstring(state, s.c_str(), s.size());
141 141
142 return 1; 142 return 1;
143 } 143 }
144 144
145 145
179 { 179 {
180 return false; 180 return false;
181 } 181 }
182 182
183 // Return the result of the HTTP request 183 // Return the result of the HTTP request
184 lua_pushstring(state, str.c_str()); 184 lua_pushlstring(state, str.c_str(), str.size());
185 185
186 return true; 186 return true;
187 } 187 }
188 188
189 189
305 305
306 void LuaContext::PushJson(const Json::Value& value) 306 void LuaContext::PushJson(const Json::Value& value)
307 { 307 {
308 if (value.isString()) 308 if (value.isString())
309 { 309 {
310 lua_pushstring(lua_, value.asCString()); 310 const std::string s = value.asString();
311 lua_pushlstring(lua_, s.c_str(), s.size());
311 } 312 }
312 else if (value.isDouble()) 313 else if (value.isDouble())
313 { 314 {
314 lua_pushnumber(lua_, value.asDouble()); 315 lua_pushnumber(lua_, value.asDouble());
315 } 316 }
354 355
355 for (Json::Value::Members::const_iterator 356 for (Json::Value::Members::const_iterator
356 it = members.begin(); it != members.end(); ++it) 357 it = members.begin(); it != members.end(); ++it)
357 { 358 {
358 // Push the index of the cell 359 // Push the index of the cell
359 lua_pushstring(lua_, it->c_str()); 360 lua_pushlstring(lua_, it->c_str(), it->size());
360 361
361 // Push the value of the cell 362 // Push the value of the cell
362 PushJson(value[*it]); 363 PushJson(value[*it]);
363 364
364 // Stores the pair in the table 365 // Stores the pair in the table