webmcp
changeset 143:6f723e60acdc
Bugfixes in JSON library
author | jbe |
---|---|
date | Wed Jul 30 02:36:37 2014 +0200 (2014-07-30) |
parents | a686ed2ce967 |
children | 0690fe79b673 |
files | libraries/json/json.c |
line diff
1.1 --- a/libraries/json/json.c Wed Jul 30 02:01:24 2014 +0200 1.2 +++ b/libraries/json/json.c Wed Jul 30 02:36:37 2014 +0200 1.3 @@ -25,24 +25,36 @@ 1.4 if (lua_isnoneornil(L, 1)) { 1.5 lua_settop(L, 0); 1.6 lua_newtable(L); 1.7 - // skip testing of existing shadow table: 1.8 - goto json_object_create_shadow_table; 1.9 - } 1.10 - // check if shadow table already exists: 1.11 - json_regfetch(L, json_shadowtbl); 1.12 - lua_pushvalue(L, 1); 1.13 - lua_rawget(L, -2); 1.14 - if (lua_isnil(L, -1)) { 1.15 - json_object_create_shadow_table: 1.16 // set shadow table: 1.17 + json_regfetch(L, json_shadowtbl); 1.18 lua_pushvalue(L, 1); 1.19 lua_newtable(L); 1.20 - lua_rawset(L, -4); 1.21 + lua_rawset(L, -3); 1.22 + } else { 1.23 + // check if shadow table already exists: 1.24 + json_regfetch(L, json_shadowtbl); 1.25 + lua_pushvalue(L, 1); 1.26 + lua_rawget(L, -2); 1.27 + if (lua_isnil(L, -1)) { 1.28 + // set shadow table and leave it on top of stack: 1.29 + lua_newtable(L); 1.30 + lua_pushvalue(L, 1); 1.31 + lua_pushvalue(L, -2); 1.32 + lua_rawset(L, -5); 1.33 + } 1.34 + for(lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { 1.35 + lua_pushvalue(L, -2); 1.36 + lua_pushnil(L); 1.37 + lua_rawset(L, 1); 1.38 + lua_pushvalue(L, -2); 1.39 + lua_pushvalue(L, -2); 1.40 + lua_rawset(L, -5); 1.41 + } 1.42 } 1.43 // discard everything but table to return: 1.44 lua_settop(L, 1); 1.45 // set metatable: 1.46 - json_regfetch(L, mt); 1.47 + json_regfetch(L, *mt); 1.48 lua_setmetatable(L, 1); 1.49 // return table: 1.50 return 1; 1.51 @@ -552,7 +564,7 @@ 1.52 lua_settop(L, 3); 1.53 json_regfetch(L, json_shadowtbl); 1.54 lua_pushvalue(L, 1); 1.55 - lua_rawget(L, -1); 1.56 + lua_rawget(L, -2); 1.57 if (lua_isnil(L, -1)) return luaL_error(L, "Shadow table not found"); 1.58 lua_replace(L, 1); 1.59 lua_settop(L, 3);