| 4125 | |
| 4126 | static cson_value *table_to_cson(Lua, int, json_conv *); |
| 4127 | static 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 | |
| 4166 | static int db_emit_int(Lua L) |
| 4167 | { |
nothing calls this directly
no test coverage detected