MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_append_object

Function json_append_object

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:621–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619}
620
621static void json_append_object(lua_State *l, json_config_t *cfg,
622 int current_depth, strbuf_t *json)
623{
624 int comma, keytype;
625
626 /* Object */
627 strbuf_append_char(json, '{');
628
629 lua_pushnil(l);
630 /* table, startkey */
631 comma = 0;
632 while (lua_next(l, -2) != 0) {
633 if (comma)
634 strbuf_append_char(json, ',');
635 else
636 comma = 1;
637
638 /* table, key, value */
639 keytype = lua_type(l, -2);
640 if (keytype == LUA_TNUMBER) {
641 strbuf_append_char(json, '"');
642 json_append_number(l, cfg, json, -2);
643 strbuf_append_mem(json, "\":", 2);
644 } else if (keytype == LUA_TSTRING) {
645 json_append_string(l, json, -2);
646 strbuf_append_char(json, ':');
647 } else {
648 json_encode_exception(l, cfg, json, -2,
649 "table key must be a number or string");
650 /* never returns */
651 }
652
653 /* table, key, value */
654 json_append_data(l, cfg, current_depth, json);
655 lua_pop(l, 1);
656 /* table, key */
657 }
658
659 strbuf_append_char(json, '}');
660}
661
662/* Serialise Lua data into JSON string. */
663static void json_append_data(lua_State *l, json_config_t *cfg,

Callers 1

json_append_dataFunction · 0.85

Calls 6

strbuf_append_charFunction · 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