| 4026 | |
| 4027 | static int cson_to_table_annotated(Lua, cson_value *, int); |
| 4028 | static int db_json_to_table(Lua lua) |
| 4029 | { |
| 4030 | int rc; |
| 4031 | if (lua_gettop(lua) < 2) { |
| 4032 | return luaL_error(lua, "bad arguments to 'json_to_table'"); |
| 4033 | } |
| 4034 | luaL_checkudata(lua, 1, dbtypes.db); |
| 4035 | int annotate = 0; |
| 4036 | if (lua_gettop(lua) == 3) { |
| 4037 | luaL_checktype(lua, 3, LUA_TTABLE); |
| 4038 | lua_pushnil(lua); |
| 4039 | int processed = 0; |
| 4040 | while (lua_next(lua, -2)) { |
| 4041 | const char *key = luabb_tostring(lua, -2); |
| 4042 | if (strcmp(key, "type_annotate") == 0) { |
| 4043 | if (luabb_type(lua, -1) == DBTYPES_LBOOLEAN) { |
| 4044 | annotate = lua_toboolean(lua, -2); |
| 4045 | processed = 1; |
| 4046 | lua_pop(lua, 1); |
| 4047 | break; |
| 4048 | } |
| 4049 | } |
| 4050 | } |
| 4051 | if (processed == 0) { |
| 4052 | return luaL_error(lua, "bad argument #2 to 'json_to_table'"); |
| 4053 | } |
| 4054 | lua_pop(lua, 1); |
| 4055 | } |
| 4056 | const char *json = luabb_tostring(lua, 2); |
| 4057 | cson_value *cson = NULL; |
| 4058 | if ((rc = cson_parse_string(&cson, json, strlen(json))) != 0) { |
| 4059 | luaL_error(lua, "Parsing JSON rc:%d err:%s", rc, cson_rc_string(rc)); |
| 4060 | } |
| 4061 | lua_newtable(lua); |
| 4062 | rc = cson_to_table_annotated(lua, cson, annotate); |
| 4063 | cson_free_value(cson); |
| 4064 | if (rc != 0) { |
| 4065 | luaL_error(lua, "bad argument #1 to json_to_table"); |
| 4066 | } |
| 4067 | return 1; |
| 4068 | } |
| 4069 | |
| 4070 | typedef struct { |
| 4071 | #define CONV_FLAG_UTF8_FATAL 0x01 |
nothing calls this directly
no test coverage detected