webmcp
changeset 174:070edea2a92f
Bugfix in json.object and json.array functions: use null-marker for nil values
author | jbe |
---|---|
date | Fri Aug 01 20:29:30 2014 +0200 (2014-08-01) |
parents | f417c4b607ed |
children | 20e393d2e6e1 |
files | libraries/json/json.c |
line diff
1.1 --- a/libraries/json/json.c Fri Aug 01 18:52:25 2014 +0200 1.2 +++ b/libraries/json/json.c Fri Aug 01 20:29:30 2014 +0200 1.3 @@ -120,6 +120,8 @@ 1.4 lua_pushvalue(L, json_convert_iterator_idx); 1.5 lua_pushvalue(L, 1); 1.6 lua_call(L, 1, 3); 1.7 + // iterate through key value pairs and store them in shadow table 1.8 + // while replacing nil values with null-marker: 1.9 while (1) { 1.10 lua_pushvalue(L, json_convert_iterfun_idx); 1.11 lua_pushvalue(L, json_convert_itertbl_idx); 1.12 @@ -129,7 +131,8 @@ 1.13 if (lua_isnil(L, -2)) break; 1.14 if (lua_type(L, -2) == (array ? LUA_TNUMBER : LUA_TSTRING)) { 1.15 lua_pushvalue(L, -2); 1.16 - lua_pushvalue(L, -2); 1.17 + if (lua_isnil(L, -2)) json_pushnullmark(L); 1.18 + else lua_pushvalue(L, -2); 1.19 lua_rawset(L, json_convert_shadow_idx); 1.20 } 1.21 lua_pop(L, 1);