webmcp

changeset 186:fbfdd4f979d5

Finished non-recursive implementation of json.export(...)
author jbe
date Sun Aug 10 18:24:05 2014 +0200 (2014-08-10)
parents 26132a017925
children 00fee67a0c27
files libraries/json/json.c
line diff
     1.1 --- a/libraries/json/json.c	Sun Aug 10 18:16:08 2014 +0200
     1.2 +++ b/libraries/json/json.c	Sun Aug 10 18:24:05 2014 +0200
     1.3 @@ -1146,6 +1146,8 @@
     1.4        lua_rawget(L, json_export_shadowtbl_idx);
     1.5        if (lua_isnil(L, -1)) lua_pop(L, 1);
     1.6        else lua_replace(L, json_export_luacontainer_idx);
     1.7 +      // reset keycount variable:
     1.8 +      keycount = 0;
     1.9        // check if type of table is still undetermined:
    1.10        if (tabletype == JSON_TABLETYPE_UNKNOWN) {
    1.11          // if yes, iterate over all keys:
    1.12 @@ -1194,16 +1196,15 @@
    1.13              if (lua_type(L, -2) == LUA_TSTRING) keycount++;
    1.14            }
    1.15          }
    1.16 -        // create a sorted list of all string keys in memory:
    1.17 +        // allocate memory for C structure containing string keys and container iteration state:
    1.18 +        container = lua_newuserdata(L, sizeof(json_container_t) + (keycount-1) * sizeof(json_key_t));
    1.19 +        // store reference on designated stack position:
    1.20 +        lua_replace(L, json_export_ccontainer_idx);
    1.21 +        // initialize C structure for container state:
    1.22 +        container->type = JSON_TABLETYPE_OBJECT;
    1.23 +        container->count = keycount;
    1.24 +        container->pos = 0;
    1.25          if (keycount) {
    1.26 -          // allocate memory for C structure containing string keys and container iteration state:
    1.27 -          container = lua_newuserdata(L, sizeof(json_container_t) + (keycount-1) * sizeof(json_key_t));
    1.28 -          // store reference on designated stack position:
    1.29 -          lua_replace(L, json_export_ccontainer_idx);
    1.30 -          // initialize C structure for container state:
    1.31 -          container->type = JSON_TABLETYPE_OBJECT;
    1.32 -          container->count = keycount;
    1.33 -          container->pos = 0;
    1.34            // copy all string keys to the C structure and reset container->pos again:
    1.35            for (lua_pushnil(L); lua_next(L, json_export_luacontainer_idx); lua_pop(L, 1)) {
    1.36              if (lua_type(L, -2) == LUA_TSTRING) {

Impressum / About Us