MCPcopy Create free account
hub / github.com/defold/defold / json_append_object

Function json_append_object

engine/script/src/luacjson/lua_cjson.c:805–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803}
804
805static void json_append_object(lua_State *l, json_config_t *cfg,
806 int current_depth, strbuf_t *json)
807{
808 int comma, keytype;
809
810 /* Object */
811 strbuf_append_char(json, '{');
812
813 lua_pushnil(l);
814 /* table, startkey */
815 comma = 0;
816 while (lua_next(l, -2) != 0) {
817 if (comma)
818 strbuf_append_char(json, ',');
819 else
820 comma = 1;
821
822 /* table, key, value */
823 keytype = lua_type(l, -2);
824 if (keytype == LUA_TNUMBER) {
825 strbuf_append_char(json, '"');
826 json_append_number(l, cfg, json, -2);
827 strbuf_append_mem(json, "\":", 2);
828 } else if (keytype == LUA_TSTRING) {
829 json_append_string(l, json, -2);
830 strbuf_append_char(json, ':');
831 } else {
832 json_encode_exception(l, cfg, json, -2,
833 "table key must be a number or string");
834 /* never returns */
835 }
836
837 /* table, key, value */
838 json_append_data(l, cfg, current_depth, json);
839 lua_pop(l, 1);
840 /* table, key */
841 }
842
843 strbuf_append_char(json, '}');
844}
845
846/* Serialise Lua data into JSON string. */
847static 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