diff options
author | Mattes D <github@xoft.cz> | 2016-07-10 12:44:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-10 12:44:09 +0200 |
commit | 443b657b7d887ef443bc0de5472519f782b1cbd2 (patch) | |
tree | 2dccada9068fa3fae2e9d19b1cdaa56f0047606b | |
parent | removed cast from BlockTrapdoor.h (#3256) (diff) | |
parent | Fixed Lua Json serializing a bool. (diff) | |
download | cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.tar cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.tar.gz cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.tar.bz2 cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.tar.lz cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.tar.xz cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.tar.zst cuberite-443b657b7d887ef443bc0de5472519f782b1cbd2.zip |
-rw-r--r-- | Server/Plugins/Debuggers/Debuggers.lua | 10 | ||||
-rw-r--r-- | src/Bindings/LuaJson.cpp | 10 |
2 files changed, 16 insertions, 4 deletions
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua index 02510c866..da375cdff 100644 --- a/Server/Plugins/Debuggers/Debuggers.lua +++ b/Server/Plugins/Debuggers/Debuggers.lua @@ -2026,22 +2026,24 @@ end function HandleConsoleTestJson(a_Split, a_EntireCmd) LOG("Testing Json parsing...") - local t1 = cJson:Parse([[{"a": 1, "b": "2", "c": [3, "4", 5] }]]) + local t1 = cJson:Parse([[{"a": 1, "b": "2", "c": [3, "4", 5], "d": true }]]) assert(t1.a == 1) assert(t1.b == "2") assert(t1.c[1] == 3) assert(t1.c[2] == "4") assert(t1.c[3] == 5) - + assert(t1.d == true) + LOG("Json parsing example 1 successful") + local t2, msg = cJson:Parse([[{"some": invalid, json}]]) assert(t2 == nil) assert(type(msg) == "string") - LOG("Error message returned: " .. msg) + LOG("Json parsing an invalid string: Error message returned: " .. msg) LOG("Json parsing test succeeded") LOG("Testing Json serializing...") - local s1 = cJson:Serialize({a = 1, b = "2", c = {3, "4", 5}}, {indentation = " "}) + local s1 = cJson:Serialize({a = 1, b = "2", c = {3, "4", 5}, d = true}, {indentation = " "}) LOG("Serialization result: " .. (s1 or "<nil>")) LOG("Json serializing test succeeded") diff --git a/src/Bindings/LuaJson.cpp b/src/Bindings/LuaJson.cpp index 4fa16273c..39a720319 100644 --- a/src/Bindings/LuaJson.cpp +++ b/src/Bindings/LuaJson.cpp @@ -160,6 +160,16 @@ static Json::Value JsonSerializeValue(cLuaState & a_LuaState) { switch (lua_type(a_LuaState, -1)) { + case LUA_TBOOLEAN: + { + bool v; + a_LuaState.GetStackValue(-1, v); + return Json::Value(v); + } + case LUA_TNIL: + { + return Json::Value(Json::nullValue); + } case LUA_TNUMBER: { lua_Number v; |