| 619 | } |
| 620 | |
| 621 | static void json_append_object(lua_State *l, json_config_t *cfg, |
| 622 | int current_depth, strbuf_t *json) |
| 623 | { |
| 624 | int comma, keytype; |
| 625 | |
| 626 | /* Object */ |
| 627 | strbuf_append_char(json, '{'); |
| 628 | |
| 629 | lua_pushnil(l); |
| 630 | /* table, startkey */ |
| 631 | comma = 0; |
| 632 | while (lua_next(l, -2) != 0) { |
| 633 | if (comma) |
| 634 | strbuf_append_char(json, ','); |
| 635 | else |
| 636 | comma = 1; |
| 637 | |
| 638 | /* table, key, value */ |
| 639 | keytype = lua_type(l, -2); |
| 640 | if (keytype == LUA_TNUMBER) { |
| 641 | strbuf_append_char(json, '"'); |
| 642 | json_append_number(l, cfg, json, -2); |
| 643 | strbuf_append_mem(json, "\":", 2); |
| 644 | } else if (keytype == LUA_TSTRING) { |
| 645 | json_append_string(l, json, -2); |
| 646 | strbuf_append_char(json, ':'); |
| 647 | } else { |
| 648 | json_encode_exception(l, cfg, json, -2, |
| 649 | "table key must be a number or string"); |
| 650 | /* never returns */ |
| 651 | } |
| 652 | |
| 653 | /* table, key, value */ |
| 654 | json_append_data(l, cfg, current_depth, json); |
| 655 | lua_pop(l, 1); |
| 656 | /* table, key */ |
| 657 | } |
| 658 | |
| 659 | strbuf_append_char(json, '}'); |
| 660 | } |
| 661 | |
| 662 | /* Serialise Lua data into JSON string. */ |
| 663 | static void json_append_data(lua_State *l, json_config_t *cfg, |
no test coverage detected