webmcp

changeset 158:d42a7a840358

Removed function json.setnull(tbl, key) from JSON library
author jbe
date Thu Jul 31 03:49:43 2014 +0200 (2014-07-31)
parents 004d2d50419e
children ddb9b9b0d210
files libraries/json/json.c
line diff
     1.1 --- a/libraries/json/json.c	Thu Jul 31 03:45:33 2014 +0200
     1.2 +++ b/libraries/json/json.c	Thu Jul 31 03:49:43 2014 +0200
     1.3 @@ -31,7 +31,6 @@
     1.4  // via lightuserdata keys and LUA_REGISTRYINDEX:
     1.5  static struct {
     1.6    JSON_REGENT shadowtbl;  // ephemeron table that maps tables to their corresponding shadow table
     1.7 -  JSON_REGENT unknownmt;  // metatable for tables that may be either JSON objects or JSON arrays
     1.8    JSON_REGENT objectmt;   // metatable for JSON objects
     1.9    JSON_REGENT arraymt;    // metatable for JSON arrays
    1.10  } json_registry;
    1.11 @@ -561,57 +560,6 @@
    1.12    return 1;
    1.13  }
    1.14  
    1.15 -// special Lua stack indicies for json_setnull function:
    1.16 -#define json_setnull_unknownmt_idx 3
    1.17 -#define json_setnull_objectmt_idx 4
    1.18 -#define json_setnull_arraymt_idx 5
    1.19 -#define json_setnull_shadowtbl_idx 6
    1.20 -
    1.21 -// sets a value in a JSON object or JSON array explicitly to null:
    1.22 -// NOTE: JSON null is different than absence of a key
    1.23 -static int json_setnull(lua_State *L) {
    1.24 -  // stack shall contain two function arguments:
    1.25 -  lua_settop(L, 2);
    1.26 -  // push unknownmt onto stack position 3:
    1.27 -  json_regfetch(L, unknownmt);
    1.28 -  // push objectmt onto stack position 4:
    1.29 -  json_regfetch(L, objectmt);
    1.30 -  // push arraymt onto stack position 5:
    1.31 -  json_regfetch(L, arraymt);
    1.32 -  // push shadowtbl onto stack position 6:
    1.33 -  json_regfetch(L, shadowtbl);
    1.34 -  // set metatable if necessary (leaves unknown number of elements on stack):
    1.35 -  if (
    1.36 -    !lua_getmetatable(L, 1) || (
    1.37 -      !lua_rawequal(L, -1, json_setnull_unknownmt_idx) &&
    1.38 -      !lua_rawequal(L, -1, json_setnull_objectmt_idx) &&
    1.39 -      !lua_rawequal(L, -1, json_setnull_arraymt_idx)
    1.40 -    )
    1.41 -  ) {
    1.42 -    lua_pushvalue(L, json_setnull_unknownmt_idx);
    1.43 -    lua_setmetatable(L, 1);
    1.44 -  }
    1.45 -  // try to get shadow table:
    1.46 -  lua_pushvalue(L, 1);
    1.47 -  lua_rawget(L, json_setnull_shadowtbl_idx);
    1.48 -  if (lua_isnil(L, -1)) {
    1.49 -    // if no shadow table is found,
    1.50 -    // create new shadow table (and leave it on top of stack):
    1.51 -    lua_newtable(L);
    1.52 -    // register shadow table:
    1.53 -    lua_pushvalue(L, 1);
    1.54 -    lua_pushvalue(L, -2);
    1.55 -    lua_rawset(L, json_setnull_shadowtbl_idx);
    1.56 -  }
    1.57 -  // push key (second argument) and null-marker after shadow table onto stack:
    1.58 -  lua_pushvalue(L, 2);
    1.59 -  json_pushnullmark(L);
    1.60 -  // store key and null-marker in shadow table:
    1.61 -  lua_rawset(L, -3);
    1.62 -  // return nothing:
    1.63 -  return 0;
    1.64 -}
    1.65 -
    1.66  // returns the length of a JSON array (or zero for a table without numeric keys):
    1.67  static int json_len(lua_State *L) {
    1.68    // stack shall contain one function argument:
    1.69 @@ -885,7 +833,6 @@
    1.70    {"get", json_get},
    1.71    {"type", json_type},
    1.72    {"isnull", json_isnull},
    1.73 -  {"setnull", json_setnull},
    1.74    {NULL, NULL}
    1.75  };
    1.76  
    1.77 @@ -913,10 +860,6 @@
    1.78    lua_newtable(L);
    1.79    // register library functions:
    1.80    luaL_setfuncs(L, json_module_functions, 0);
    1.81 -  // create and store unknownmt:
    1.82 -  lua_newtable(L);
    1.83 -  luaL_setfuncs(L, json_metatable_functions, 0);
    1.84 -  json_regstore(L, unknownmt);
    1.85    // create and store objectmt:
    1.86    lua_newtable(L);
    1.87    luaL_setfuncs(L, json_metatable_functions, 0);

Impressum / About Us