comparison OrthancFramework/Sources/Lua/LuaContext.cpp @ 4392:3af1d763763a

confining Json::Reader and Json::*Writer into Toolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Dec 2020 18:09:47 +0100
parents b30a8de92ad9
children f7104e9d044c
comparison
equal deleted inserted replaced
4391:0c4ff5609548 4392:3af1d763763a
111 } 111 }
112 112
113 const char* str = lua_tostring(state, 1); 113 const char* str = lua_tostring(state, 1);
114 114
115 Json::Value value; 115 Json::Value value;
116 Json::Reader reader; 116 if (Toolbox::ReadJson(value, str, strlen(str)))
117 if (reader.parse(str, str + strlen(str), value))
118 { 117 {
119 that.PushJson(value); 118 that.PushJson(value);
120 } 119 }
121 else 120 else
122 { 121 {
146 } 145 }
147 146
148 Json::Value json; 147 Json::Value json;
149 that.GetJson(json, state, 1, keepStrings); 148 that.GetJson(json, state, 1, keepStrings);
150 149
151 Json::FastWriter writer; 150 std::string s;
152 std::string s = writer.write(json); 151 Toolbox::WriteJson(s, json, true /* fast */);
153 lua_pushlstring(state, s.c_str(), s.size()); 152 lua_pushlstring(state, s.c_str(), s.size());
154 153
155 return 1; 154 return 1;
156 } 155 }
157 156
633 const std::string& command) 632 const std::string& command)
634 { 633 {
635 std::string s; 634 std::string s;
636 ExecuteInternal(&s, command); 635 ExecuteInternal(&s, command);
637 636
638 Json::Reader reader; 637 if (!Toolbox::ReadJson(output, s))
639 if (!reader.parse(s, output))
640 { 638 {
641 throw OrthancException(ErrorCode_BadJson); 639 throw OrthancException(ErrorCode_BadJson);
642 } 640 }
643 } 641 }
644 642