MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / json_parse_array_context

Function json_parse_array_context

LuaSTGPlus/LuaExtensions/cjson4lua/lua_cjson.c:1189–1224  ·  view source on GitHub ↗

Handle the array context */

Source from the content-addressed store, hash-verified

1187
1188/* Handle the array context */
1189static 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 */
1227static void json_process_value(lua_State *l, json_parse_t *json,

Callers 1

json_process_valueFunction · 0.85

Calls 5

json_decode_descendFunction · 0.85
json_next_tokenFunction · 0.85
json_decode_ascendFunction · 0.85
json_process_valueFunction · 0.85
json_throw_parse_errorFunction · 0.85

Tested by

no test coverage detected