MCPcopy Create free account
hub / github.com/defold/defold / json_parse_array_context

Function json_parse_array_context

engine/script/src/luacjson/lua_cjson.c:1476–1520  ·  view source on GitHub ↗

Handle the array context */

Source from the content-addressed store, hash-verified

1474
1475/* Handle the array context */
1476static int json_parse_array_context(lua_State *l, json_parse_t *json)
1477{
1478 json_token_t token;
1479 int i;
1480
1481 /* 2 slots required:
1482 * .., table, value */
1483 json_decode_descend(l, json, 2);
1484
1485 lua_newtable(l);
1486
1487 /* set array_mt on the table at the top of the stack */
1488 if (json->cfg->decode_array_with_array_mt) {
1489 lua_pushlightuserdata(l, json_lightudata_mask(&json_array));
1490 lua_rawget(l, LUA_REGISTRYINDEX);
1491 lua_setmetatable(l, -2);
1492 }
1493
1494 json_next_token(json, &token);
1495
1496 /* Handle empty arrays */
1497 if (token.type == T_ARR_END) {
1498 json_decode_ascend(json);
1499 return 1;
1500 }
1501
1502 for (i = 1; ; i++) {
1503 if (!json_process_value(l, json, &token))
1504 return 0;
1505 lua_rawseti(l, -2, i); /* arr[i] = value */
1506
1507 json_next_token(json, &token);
1508
1509 if (token.type == T_ARR_END) {
1510 json_decode_ascend(json);
1511 return 1;
1512 }
1513
1514 if (token.type != T_COMMA)
1515 return json_throw_parse_error(l, json, "comma or array end", &token);
1516
1517 json_next_token(json, &token);
1518 }
1519 return 1;
1520}
1521
1522/* Handle the "value" context */
1523static int json_process_value(lua_State *l, json_parse_t *json,

Callers 1

json_process_valueFunction · 0.85

Calls 9

json_decode_descendFunction · 0.85
lua_pushlightuserdataFunction · 0.85
lua_rawgetFunction · 0.85
lua_setmetatableFunction · 0.85
json_next_tokenFunction · 0.85
json_decode_ascendFunction · 0.85
json_process_valueFunction · 0.85
lua_rawsetiFunction · 0.85
json_throw_parse_errorFunction · 0.85

Tested by

no test coverage detected