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

Function json_append_data

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:663–704  ·  view source on GitHub ↗

Serialise Lua data into JSON string. */

Source from the content-addressed store, hash-verified

661
662/* Serialise Lua data into JSON string. */
663static void json_append_data(lua_State *l, json_config_t *cfg,
664 int current_depth, strbuf_t *json)
665{
666 int len;
667
668 switch (lua_type(l, -1)) {
669 case LUA_TSTRING:
670 json_append_string(l, json, -1);
671 break;
672 case LUA_TNUMBER:
673 json_append_number(l, cfg, json, -1);
674 break;
675 case LUA_TBOOLEAN:
676 if (lua_toboolean(l, -1))
677 strbuf_append_mem(json, "true", 4);
678 else
679 strbuf_append_mem(json, "false", 5);
680 break;
681 case LUA_TTABLE:
682 current_depth++;
683 json_check_encode_depth(l, cfg, current_depth, json);
684 len = lua_array_length(l, cfg, json);
685 if (len > 0)
686 json_append_array(l, cfg, current_depth, json, len);
687 else
688 json_append_object(l, cfg, current_depth, json);
689 break;
690 case LUA_TNIL:
691 strbuf_append_mem(json, "null", 4);
692 break;
693 case LUA_TLIGHTUSERDATA:
694 if (lua_touserdata(l, -1) == NULL) {
695 strbuf_append_mem(json, "null", 4);
696 break;
697 }
698 default:
699 /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD,
700 * and LUA_TLIGHTUSERDATA) cannot be serialised */
701 json_encode_exception(l, cfg, json, -1, "type not supported");
702 /* never returns */
703 }
704}
705
706static int json_encode(lua_State *l)
707{

Callers 3

json_append_arrayFunction · 0.85
json_append_objectFunction · 0.85
json_encodeFunction · 0.85

Calls 8

json_append_stringFunction · 0.85
json_append_numberFunction · 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
json_encode_exceptionFunction · 0.85

Tested by

no test coverage detected