MCPcopy Create free account
hub / github.com/axmolengine/axmol / json_append_object

Function json_append_object

3rdparty/lua/lua-cjson/lua_cjson.c:646–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

644}
645
646static void json_append_object(lua_State *l, json_config_t *cfg,
647 int current_depth, strbuf_t *json)
648{
649 int comma, keytype;
650
651 /* Object */
652 strbuf_append_char(json, '{');
653
654 lua_pushnil(l);
655 /* table, startkey */
656 comma = 0;
657 while (lua_next(l, -2) != 0) {
658 if (comma)
659 strbuf_append_char(json, ',');
660 else
661 comma = 1;
662
663 /* table, key, value */
664 keytype = lua_type(l, -2);
665 if (keytype == LUA_TNUMBER) {
666 strbuf_append_char(json, '"');
667 json_append_number(l, cfg, json, -2);
668 strbuf_append_mem(json, "\":", 2);
669 } else if (keytype == LUA_TSTRING) {
670 json_append_string(l, json, -2);
671 strbuf_append_char(json, ':');
672 } else {
673 json_encode_exception(l, cfg, json, -2,
674 "table key must be a number or string");
675 /* never returns */
676 }
677
678 /* table, key, value */
679 json_append_data(l, cfg, current_depth, json);
680 lua_pop(l, 1);
681 /* table, key */
682 }
683
684 strbuf_append_char(json, '}');
685}
686
687/* Serialise Lua data into JSON string. */
688static void json_append_data(lua_State *l, json_config_t *cfg,

Callers 1

json_append_dataFunction · 0.85

Calls 9

strbuf_append_charFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_typeFunction · 0.85
json_append_numberFunction · 0.85
strbuf_append_memFunction · 0.85
json_append_stringFunction · 0.85
json_encode_exceptionFunction · 0.85
json_append_dataFunction · 0.85

Tested by

no test coverage detected