webmcp
diff libraries/json/json.c @ 184:1f925cb34299
Fixed comma setting in json.export(...)
author | jbe |
---|---|
date | Sat Aug 09 20:07:12 2014 +0200 (2014-08-09) |
parents | f7c1869b5b32 |
children | 26132a017925 |
line diff
1.1 --- a/libraries/json/json.c Sat Aug 09 19:39:16 2014 +0200 1.2 +++ b/libraries/json/json.c Sat Aug 09 20:07:12 2014 +0200 1.3 @@ -1237,8 +1237,9 @@ 1.4 return luaL_error(L, "JSON export not possible for values of type \"%s\"", lua_typename(L, lua_type(L, json_export_value_idx))); 1.5 } 1.6 if (container) { 1.7 - // add colon where necessary: 1.8 + // add colon or comma where necessary: 1.9 if (containerkey) luaL_addchar(&buf, ':'); 1.10 + json_export_container: 1.11 switch (container->type) { 1.12 case JSON_TABLETYPE_OBJECT: 1.13 if (container->pos < container->count) { 1.14 @@ -1273,6 +1274,7 @@ 1.15 container = lua_touserdata(L, json_export_ccontainer_idx); 1.16 lua_rawgeti(L, json_export_stackswap_idx, stackswapidx--); 1.17 lua_replace(L, json_export_luacontainer_idx); 1.18 + goto json_export_container; 1.19 } else { 1.20 // for pretty results, add final newline character if outermost container is processed: 1.21 if (pretty) luaL_addchar(&buf, '\n'); 1.22 @@ -1280,24 +1282,25 @@ 1.23 return 1; 1.24 } 1.25 } 1.26 - /* 1.27 - if (containerkey || container->type == JSON_TABLETYPE_ARRAY) { 1.28 - // add comma where necessary: 1.29 - if (container->pos > 1) luaL_addchar(&buf, ','); 1.30 - // handle indentation for pretty results: 1.31 - if (pretty) { 1.32 - if (containerkey) { 1.33 - luaL_addchar(&buf, ' '); 1.34 - } else { 1.35 - luaL_addchar(&buf, '\n'); 1.36 - for (i=0; i<level; i++) { 1.37 - lua_pushvalue(L, json_export_indentstring_idx); 1.38 - luaL_addvalue(&buf); 1.39 - } 1.40 + if ( 1.41 + container->type == JSON_TABLETYPE_OBJECT ? ( 1.42 + container->pos && containerkey 1.43 + ) : ( 1.44 + container->pos > 1 1.45 + ) 1.46 + ) luaL_addchar(&buf, ','); 1.47 + // handle indentation for pretty results: 1.48 + if (pretty) { 1.49 + if (containerkey) { 1.50 + luaL_addchar(&buf, ' '); 1.51 + } else { 1.52 + luaL_addchar(&buf, '\n'); 1.53 + for (i=0; i<level; i++) { 1.54 + lua_pushvalue(L, json_export_indentstring_idx); 1.55 + luaL_addvalue(&buf); 1.56 } 1.57 } 1.58 } 1.59 - */ 1.60 } else { 1.61 luaL_pushresult(&buf); 1.62 return 1;