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

Function json_encode

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

Source from the content-addressed store, hash-verified

931
932#if 0 // DEFOLD
933static int json_encode(lua_State *l)
934{
935 json_config_t *cfg = json_fetch_config(l);
936 strbuf_t local_encode_buf;
937 strbuf_t *encode_buf;
938 char *json;
939 int len;
940
941 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
942
943 if (!cfg->encode_keep_buffer) {
944 /* Use private buffer */
945 encode_buf = &local_encode_buf;
946 strbuf_init(encode_buf, 0);
947 } else {
948 /* Reuse existing buffer */
949 encode_buf = &cfg->encode_buf;
950 strbuf_reset(encode_buf);
951 }
952
953 json_append_data(l, cfg, 0, encode_buf);
954 json = strbuf_string(encode_buf, &len);
955
956 lua_pushlstring(l, json, len);
957
958 if (!cfg->encode_keep_buffer)
959 strbuf_free(encode_buf);
960
961 return 1;
962}
963#endif // DEFOLD
964
965///////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 8

json_fetch_configFunction · 0.85
lua_gettopFunction · 0.85
strbuf_initFunction · 0.85
strbuf_resetFunction · 0.85
json_append_dataFunction · 0.85
strbuf_stringFunction · 0.85
lua_pushlstringFunction · 0.85
strbuf_freeFunction · 0.85

Tested by

no test coverage detected