Handle the array context */
| 1217 | |
| 1218 | /* Handle the array context */ |
| 1219 | static void json_parse_array_context(lua_State *l, json_parse_t *json) |
| 1220 | { |
| 1221 | json_token_t token; |
| 1222 | int i; |
| 1223 | |
| 1224 | /* 2 slots required: |
| 1225 | * .., table, value */ |
| 1226 | json_decode_descend(l, json, 2); |
| 1227 | |
| 1228 | lua_newtable(l); |
| 1229 | |
| 1230 | json_next_token(json, &token); |
| 1231 | |
| 1232 | /* Handle empty arrays */ |
| 1233 | if (token.type == T_ARR_END) { |
| 1234 | json_decode_ascend(json); |
| 1235 | return; |
| 1236 | } |
| 1237 | |
| 1238 | for (i = 1; ; i++) { |
| 1239 | json_process_value(l, json, &token); |
| 1240 | lua_rawseti(l, -2, i); /* arr[i] = value */ |
| 1241 | |
| 1242 | json_next_token(json, &token); |
| 1243 | |
| 1244 | if (token.type == T_ARR_END) { |
| 1245 | json_decode_ascend(json); |
| 1246 | return; |
| 1247 | } |
| 1248 | |
| 1249 | if (token.type != T_COMMA) |
| 1250 | json_throw_parse_error(l, json, "comma or array end", &token); |
| 1251 | |
| 1252 | json_next_token(json, &token); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | /* Handle the "value" context */ |
| 1257 | static void json_process_value(lua_State *l, json_parse_t *json, |
no test coverage detected