encode a lua table to a JSON string * Encode a lua table to a JSON string. * A Lua error is raised for syntax errors. * * @name json.encode * @param tbl [type:table] lua table to encode * @param [options] [type:table] table with encode options * * - [type:string] `encode_empty_table_as_object`: whether to encode an empty table as an JSON object or array (def
| 178 | * ``` |
| 179 | */ |
| 180 | static int Json_Encode(lua_State* L) |
| 181 | { |
| 182 | int top = lua_gettop(L); |
| 183 | if (top == 0) |
| 184 | { |
| 185 | luaL_error(L, "json.encode requires one argument."); |
| 186 | } |
| 187 | |
| 188 | char* json = 0; |
| 189 | size_t json_length = 0; |
| 190 | if (LuaToJson(L, 1, 2, &json, &json_length)) |
| 191 | { |
| 192 | lua_pushlstring(L, json, json_length); |
| 193 | free(json); |
| 194 | } else { |
| 195 | lua_pushnil(L); |
| 196 | } |
| 197 | |
| 198 | assert(top + 1 == lua_gettop(L)); |
| 199 | return 1; |
| 200 | } |
| 201 | |
| 202 | /*# null |
| 203 | * Represents the null primitive from a json file |
nothing calls this directly
no test coverage detected