| 803 | } |
| 804 | |
| 805 | static void json_append_object(lua_State *l, json_config_t *cfg, |
| 806 | int current_depth, strbuf_t *json) |
| 807 | { |
| 808 | int comma, keytype; |
| 809 | |
| 810 | /* Object */ |
| 811 | strbuf_append_char(json, '{'); |
| 812 | |
| 813 | lua_pushnil(l); |
| 814 | /* table, startkey */ |
| 815 | comma = 0; |
| 816 | while (lua_next(l, -2) != 0) { |
| 817 | if (comma) |
| 818 | strbuf_append_char(json, ','); |
| 819 | else |
| 820 | comma = 1; |
| 821 | |
| 822 | /* table, key, value */ |
| 823 | keytype = lua_type(l, -2); |
| 824 | if (keytype == LUA_TNUMBER) { |
| 825 | strbuf_append_char(json, '"'); |
| 826 | json_append_number(l, cfg, json, -2); |
| 827 | strbuf_append_mem(json, "\":", 2); |
| 828 | } else if (keytype == LUA_TSTRING) { |
| 829 | json_append_string(l, json, -2); |
| 830 | strbuf_append_char(json, ':'); |
| 831 | } else { |
| 832 | json_encode_exception(l, cfg, json, -2, |
| 833 | "table key must be a number or string"); |
| 834 | /* never returns */ |
| 835 | } |
| 836 | |
| 837 | /* table, key, value */ |
| 838 | json_append_data(l, cfg, current_depth, json); |
| 839 | lua_pop(l, 1); |
| 840 | /* table, key */ |
| 841 | } |
| 842 | |
| 843 | strbuf_append_char(json, '}'); |
| 844 | } |
| 845 | |
| 846 | /* Serialise Lua data into JSON string. */ |
| 847 | static void json_append_data(lua_State *l, json_config_t *cfg, |
no test coverage detected