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

Function json_encode

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:706–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704}
705
706static int json_encode(lua_State *l)
707{
708 json_config_t *cfg = json_fetch_config(l);
709 strbuf_t local_encode_buf;
710 strbuf_t *encode_buf;
711 char *json;
712 int len;
713
714 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
715
716 if (!cfg->encode_keep_buffer) {
717 /* Use private buffer */
718 encode_buf = &local_encode_buf;
719 strbuf_init(encode_buf, 0);
720 } else {
721 /* Reuse existing buffer */
722 encode_buf = &cfg->encode_buf;
723 strbuf_reset(encode_buf);
724 }
725
726 json_append_data(l, cfg, 0, encode_buf);
727 json = strbuf_string(encode_buf, &len);
728
729 lua_pushlstring(l, json, len);
730
731 if (!cfg->encode_keep_buffer)
732 strbuf_free(encode_buf);
733
734 return 1;
735}
736
737/* ===== DECODING ===== */
738

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected