# HG changeset patch # User jbe # Date 1406680597 -7200 # Node ID 6f723e60acdccc0e2bcc308ae3fc8138531c4222 # Parent a686ed2ce96764fb557e2256eece89bf3bc2c1f4 Bugfixes in JSON library diff -r a686ed2ce967 -r 6f723e60acdc libraries/json/json.c --- a/libraries/json/json.c Wed Jul 30 02:01:24 2014 +0200 +++ b/libraries/json/json.c Wed Jul 30 02:36:37 2014 +0200 @@ -25,24 +25,36 @@ if (lua_isnoneornil(L, 1)) { lua_settop(L, 0); lua_newtable(L); - // skip testing of existing shadow table: - goto json_object_create_shadow_table; - } - // check if shadow table already exists: - json_regfetch(L, json_shadowtbl); - lua_pushvalue(L, 1); - lua_rawget(L, -2); - if (lua_isnil(L, -1)) { - json_object_create_shadow_table: // set shadow table: + json_regfetch(L, json_shadowtbl); lua_pushvalue(L, 1); lua_newtable(L); - lua_rawset(L, -4); + lua_rawset(L, -3); + } else { + // check if shadow table already exists: + json_regfetch(L, json_shadowtbl); + lua_pushvalue(L, 1); + lua_rawget(L, -2); + if (lua_isnil(L, -1)) { + // set shadow table and leave it on top of stack: + lua_newtable(L); + lua_pushvalue(L, 1); + lua_pushvalue(L, -2); + lua_rawset(L, -5); + } + for(lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { + lua_pushvalue(L, -2); + lua_pushnil(L); + lua_rawset(L, 1); + lua_pushvalue(L, -2); + lua_pushvalue(L, -2); + lua_rawset(L, -5); + } } // discard everything but table to return: lua_settop(L, 1); // set metatable: - json_regfetch(L, mt); + json_regfetch(L, *mt); lua_setmetatable(L, 1); // return table: return 1; @@ -552,7 +564,7 @@ lua_settop(L, 3); json_regfetch(L, json_shadowtbl); lua_pushvalue(L, 1); - lua_rawget(L, -1); + lua_rawget(L, -2); if (lua_isnil(L, -1)) return luaL_error(L, "Shadow table not found"); lua_replace(L, 1); lua_settop(L, 3);