# HG changeset patch # User jbe # Date 1406771383 -7200 # Node ID d42a7a84035886ef379ed73590d6511679d1b1ce # Parent 004d2d50419e619307196825fde1a710d3c1f58a Removed function json.setnull(tbl, key) from JSON library diff -r 004d2d50419e -r d42a7a840358 libraries/json/json.c --- a/libraries/json/json.c Thu Jul 31 03:45:33 2014 +0200 +++ b/libraries/json/json.c Thu Jul 31 03:49:43 2014 +0200 @@ -31,7 +31,6 @@ // via lightuserdata keys and LUA_REGISTRYINDEX: static struct { JSON_REGENT shadowtbl; // ephemeron table that maps tables to their corresponding shadow table - JSON_REGENT unknownmt; // metatable for tables that may be either JSON objects or JSON arrays JSON_REGENT objectmt; // metatable for JSON objects JSON_REGENT arraymt; // metatable for JSON arrays } json_registry; @@ -561,57 +560,6 @@ return 1; } -// special Lua stack indicies for json_setnull function: -#define json_setnull_unknownmt_idx 3 -#define json_setnull_objectmt_idx 4 -#define json_setnull_arraymt_idx 5 -#define json_setnull_shadowtbl_idx 6 - -// sets a value in a JSON object or JSON array explicitly to null: -// NOTE: JSON null is different than absence of a key -static int json_setnull(lua_State *L) { - // stack shall contain two function arguments: - lua_settop(L, 2); - // push unknownmt onto stack position 3: - json_regfetch(L, unknownmt); - // push objectmt onto stack position 4: - json_regfetch(L, objectmt); - // push arraymt onto stack position 5: - json_regfetch(L, arraymt); - // push shadowtbl onto stack position 6: - json_regfetch(L, shadowtbl); - // set metatable if necessary (leaves unknown number of elements on stack): - if ( - !lua_getmetatable(L, 1) || ( - !lua_rawequal(L, -1, json_setnull_unknownmt_idx) && - !lua_rawequal(L, -1, json_setnull_objectmt_idx) && - !lua_rawequal(L, -1, json_setnull_arraymt_idx) - ) - ) { - lua_pushvalue(L, json_setnull_unknownmt_idx); - lua_setmetatable(L, 1); - } - // try to get shadow table: - lua_pushvalue(L, 1); - lua_rawget(L, json_setnull_shadowtbl_idx); - if (lua_isnil(L, -1)) { - // if no shadow table is found, - // create new shadow table (and leave it on top of stack): - lua_newtable(L); - // register shadow table: - lua_pushvalue(L, 1); - lua_pushvalue(L, -2); - lua_rawset(L, json_setnull_shadowtbl_idx); - } - // push key (second argument) and null-marker after shadow table onto stack: - lua_pushvalue(L, 2); - json_pushnullmark(L); - // store key and null-marker in shadow table: - lua_rawset(L, -3); - // return nothing: - return 0; -} - // returns the length of a JSON array (or zero for a table without numeric keys): static int json_len(lua_State *L) { // stack shall contain one function argument: @@ -885,7 +833,6 @@ {"get", json_get}, {"type", json_type}, {"isnull", json_isnull}, - {"setnull", json_setnull}, {NULL, NULL} }; @@ -913,10 +860,6 @@ lua_newtable(L); // register library functions: luaL_setfuncs(L, json_module_functions, 0); - // create and store unknownmt: - lua_newtable(L); - luaL_setfuncs(L, json_metatable_functions, 0); - json_regstore(L, unknownmt); // create and store objectmt: lua_newtable(L); luaL_setfuncs(L, json_metatable_functions, 0);