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