| 5317 | } |
| 5318 | |
| 5319 | static int cson_to_table(Lua lua, cson_value *v) |
| 5320 | { |
| 5321 | if (cson_value_is_object(v)) { |
| 5322 | cson_object *o = cson_value_get_object(v); |
| 5323 | cson_object_iterator i; |
| 5324 | cson_object_iter_init(o, &i); |
| 5325 | cson_kvp *kv; |
| 5326 | /* Make sure we have enough space to store "key" and "value". */ |
| 5327 | if (lua_checkstack(lua, 2) == 0) |
| 5328 | return -1; |
| 5329 | while ((kv = cson_object_iter_next(&i)) != NULL) { |
| 5330 | lua_pushstring(lua, cson_string_cstr(cson_kvp_key(kv))); |
| 5331 | if (cson_push_value(lua, cson_kvp_value(kv)) != 0) return -1; |
| 5332 | lua_settable(lua, -3); |
| 5333 | } |
| 5334 | } else if (cson_value_is_array(v)) { |
| 5335 | cson_array *a = cson_value_get_array(v); |
| 5336 | unsigned int i, len = cson_array_length_get(a); |
| 5337 | /* |
| 5338 | * Make sure we have enough space to store one value to be pushed into |
| 5339 | * the array. |
| 5340 | */ |
| 5341 | if (lua_checkstack(lua, 1) == 0) |
| 5342 | return -1; |
| 5343 | for (i = 0; i < len; ++i) { |
| 5344 | if (cson_push_value(lua, cson_array_get(a, i)) != 0) return -1; |
| 5345 | lua_rawseti(lua, -2, i + 1); |
| 5346 | } |
| 5347 | } else { |
| 5348 | return -1; |
| 5349 | } |
| 5350 | return 0; |
| 5351 | } |
| 5352 | |
| 5353 | static int cson_push_null(Lua L, const char *type) |
| 5354 | { |
no test coverage detected