MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / db_table_to_json

Function db_table_to_json

lua/sp.c:4127–4164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4125
4126static cson_value *table_to_cson(Lua, int, json_conv *);
4127static int db_table_to_json(Lua L)
4128{
4129 luaL_checkudata(L, 1, dbtypes.db);
4130 luaL_checktype(L, 2, LUA_TTABLE);
4131 json_conv conv = {0};
4132 if (lua_gettop(L) == 3) {
4133 luaL_checktype(L, 3, LUA_TTABLE);
4134 lua_pushnil(L);
4135 int processed = 0;
4136 while (lua_next(L, -2)) {
4137 if (process_json_conv(L, &conv) != 0) {
4138 out:
4139 return luaL_error(L, "bad argument #2 to 'table_to_json'");
4140 }
4141 processed = 1;
4142 lua_pop(L, 1);
4143 }
4144 if (processed == 0) goto out;
4145 lua_pop(L, 1);
4146 }
4147 if ((conv.flag & CONV_FLAG_UTF8_MASK) == 0)
4148 conv.flag |= CONV_FLAG_UTF8_FATAL;
4149 cson_value *cson = table_to_cson(L, 0, &conv);
4150 if (cson == NULL) {
4151 if (conv.reason & (CONV_REASON_UTF8_FATAL | CONV_REASON_ARGS_FATAL)) {
4152 return luaL_error(L, conv.error);
4153 }
4154 lua_pushnil(L); // CONV_REASON_UTF8_NIL
4155 } else {
4156 cson_buffer buf;
4157 cson_output_buffer(cson, &buf);
4158 lua_pushlstring(L, (char *)buf.mem, buf.used);
4159 cson_free_value(cson);
4160 }
4161 // non-zero rc if nil'd, truncated or hexified cstring
4162 lua_pushinteger(L, conv.reason);
4163 return 2;
4164}
4165
4166static int db_emit_int(Lua L)
4167{

Callers

nothing calls this directly

Calls 12

luaL_checkudataFunction · 0.85
luaL_checktypeFunction · 0.85
lua_gettopFunction · 0.85
lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
process_json_convFunction · 0.85
luaL_errorFunction · 0.85
table_to_csonFunction · 0.85
cson_output_bufferFunction · 0.85
lua_pushlstringFunction · 0.85
cson_free_valueFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected