| 5468 | } |
| 5469 | |
| 5470 | static int cson_to_table_annotated(Lua L, cson_value *val, int annotate) |
| 5471 | { |
| 5472 | if (annotate == 0) return cson_to_table(L, val); |
| 5473 | if (!cson_value_is_object(val)) return -1; |
| 5474 | if (lua_checkstack(L, 5) == 0) return -1; |
| 5475 | cson_object *o = cson_value_get_object(val); |
| 5476 | cson_value *t = cson_object_get(o, json_type); |
| 5477 | cson_value *v = cson_object_get(o, json_value); |
| 5478 | if (t == NULL || v == NULL || !cson_value_is_string(t)) return -1; |
| 5479 | char const *type = cson_value_get_cstr(t); |
| 5480 | if (strcmp(type, "object") == 0) { |
| 5481 | cson_object *o = cson_value_get_object(v); |
| 5482 | cson_object_iterator i; |
| 5483 | cson_object_iter_init(o, &i); |
| 5484 | cson_kvp *kv; |
| 5485 | while ((kv = cson_object_iter_next(&i)) != NULL) { |
| 5486 | lua_pushstring(L, cson_string_cstr(cson_kvp_key(kv))); |
| 5487 | if (cson_push_value_annotated(L, cson_kvp_value(kv)) != 0) |
| 5488 | return -1; |
| 5489 | lua_settable(L, -3); |
| 5490 | } |
| 5491 | } else if (strcmp(type, "array") == 0) { |
| 5492 | cson_array *a = cson_value_get_array(v); |
| 5493 | unsigned int i, len = cson_array_length_get(a); |
| 5494 | for (i = 0; i < len; ++i) { |
| 5495 | if (cson_push_value_annotated(L, cson_array_get(a, i)) != 0) |
| 5496 | return -1; |
| 5497 | lua_rawseti(L, -2, i + 1); |
| 5498 | } |
| 5499 | } else { |
| 5500 | return -1; |
| 5501 | } |
| 5502 | return 0; |
| 5503 | } |
| 5504 | |
| 5505 | // value to convert is on top of stack |
| 5506 | static cson_value *table_to_cson_array(Lua L, int lvl, json_conv *conv) |
no test coverage detected