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

Function json_append_data

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

Serialise Lua data into JSON string. */

Source from the content-addressed store, hash-verified

686
687/* Serialise Lua data into JSON string. */
688static void json_append_data(lua_State *l, json_config_t *cfg,
689 int current_depth, strbuf_t *json)
690{
691 int len;
692
693 switch (lua_type(l, -1)) {
694 case LUA_TSTRING:
695 json_append_string(l, json, -1);
696 break;
697 case LUA_TNUMBER:
698 json_append_number(l, cfg, json, -1);
699 break;
700 case LUA_TBOOLEAN:
701 if (lua_toboolean(l, -1))
702 strbuf_append_mem(json, "true", 4);
703 else
704 strbuf_append_mem(json, "false", 5);
705 break;
706 case LUA_TTABLE:
707 current_depth++;
708 json_check_encode_depth(l, cfg, current_depth, json);
709 len = lua_array_length(l, cfg, json);
710 if (len > 0)
711 json_append_array(l, cfg, current_depth, json, len);
712 else
713 json_append_object(l, cfg, current_depth, json);
714 break;
715 case LUA_TNIL:
716 strbuf_append_mem(json, "null", 4);
717 break;
718 case LUA_TLIGHTUSERDATA:
719 if (lua_touserdata(l, -1) == NULL) {
720 strbuf_append_mem(json, "null", 4);
721 break;
722 }
723 default:
724 /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD,
725 * and LUA_TLIGHTUSERDATA) cannot be serialised */
726 json_encode_exception(l, cfg, json, -1, "type not supported");
727 /* never returns */
728 }
729}
730
731static int json_encode(lua_State *l)
732{

Callers 3

json_append_arrayFunction · 0.85
json_append_objectFunction · 0.85
json_encodeFunction · 0.85

Calls 11

lua_typeFunction · 0.85
json_append_stringFunction · 0.85
json_append_numberFunction · 0.85
lua_tobooleanFunction · 0.85
strbuf_append_memFunction · 0.85
json_check_encode_depthFunction · 0.85
lua_array_lengthFunction · 0.85
json_append_arrayFunction · 0.85
json_append_objectFunction · 0.85
lua_touserdataFunction · 0.85
json_encode_exceptionFunction · 0.85

Tested by

no test coverage detected