Handle the array context */
| 1184 | |
| 1185 | /* Handle the array context */ |
| 1186 | static void json_parse_array_context(lua_State *l, json_parse_t *json) |
| 1187 | { |
| 1188 | json_token_t token; |
| 1189 | int i; |
| 1190 | |
| 1191 | /* 2 slots required: |
| 1192 | * .., table, value */ |
| 1193 | json_decode_descend(l, json, 2); |
| 1194 | |
| 1195 | lua_newtable(l); |
| 1196 | |
| 1197 | json_next_token(json, &token); |
| 1198 | |
| 1199 | /* Handle empty arrays */ |
| 1200 | if (token.type == T_ARR_END) { |
| 1201 | json_decode_ascend(json); |
| 1202 | return; |
| 1203 | } |
| 1204 | |
| 1205 | for (i = 1; ; i++) { |
| 1206 | json_process_value(l, json, &token); |
| 1207 | lua_rawseti(l, -2, i); /* arr[i] = value */ |
| 1208 | |
| 1209 | json_next_token(json, &token); |
| 1210 | |
| 1211 | if (token.type == T_ARR_END) { |
| 1212 | json_decode_ascend(json); |
| 1213 | return; |
| 1214 | } |
| 1215 | |
| 1216 | if (token.type != T_COMMA) |
| 1217 | json_throw_parse_error(l, json, "comma or array end", &token); |
| 1218 | |
| 1219 | json_next_token(json, &token); |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | /* Handle the "value" context */ |
| 1224 | static void json_process_value(lua_State *l, json_parse_t *json, |
no test coverage detected