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

Function json_encode

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

Source from the content-addressed store, hash-verified

729}
730
731static int json_encode(lua_State *l)
732{
733 json_config_t *cfg = json_fetch_config(l);
734 strbuf_t local_encode_buf;
735 strbuf_t *encode_buf;
736 char *json;
737 int len;
738
739 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
740
741 if (!cfg->encode_keep_buffer) {
742 /* Use private buffer */
743 encode_buf = &local_encode_buf;
744 strbuf_init(encode_buf, 0);
745 } else {
746 /* Reuse existing buffer */
747 encode_buf = &cfg->encode_buf;
748 strbuf_reset(encode_buf);
749 }
750
751 json_append_data(l, cfg, 0, encode_buf);
752 json = strbuf_string(encode_buf, &len);
753
754 lua_pushlstring(l, json, len);
755
756 if (!cfg->encode_keep_buffer)
757 strbuf_free(encode_buf);
758
759 return 1;
760}
761
762/* ===== DECODING ===== */
763

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