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

Function json_parse_object_context

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

Source from the content-addressed store, hash-verified

1421}
1422
1423static int json_parse_object_context(lua_State *l, json_parse_t *json)
1424{
1425 json_token_t token;
1426
1427 /* 3 slots required:
1428 * .., table, key, value */
1429 json_decode_descend(l, json, 3);
1430
1431 lua_newtable(l);
1432
1433 json_next_token(json, &token);
1434
1435 /* Handle empty objects */
1436 if (token.type == T_OBJ_END) {
1437 json_decode_ascend(json);
1438 return 1;
1439 }
1440
1441 while (1) {
1442 if (token.type != T_STRING)
1443 return json_throw_parse_error(l, json, "object key string", &token);
1444
1445 /* Push key */
1446 lua_pushlstring(l, token.value.string, token.string_len);
1447
1448 json_next_token(json, &token);
1449 if (token.type != T_COLON)
1450 return json_throw_parse_error(l, json, "colon", &token);
1451
1452 /* Fetch value */
1453 json_next_token(json, &token);
1454 if (!json_process_value(l, json, &token))
1455 return 0;
1456
1457 /* Set key = value */
1458 lua_rawset(l, -3);
1459
1460 json_next_token(json, &token);
1461
1462 if (token.type == T_OBJ_END) {
1463 json_decode_ascend(json);
1464 return 1;
1465 }
1466
1467 if (token.type != T_COMMA)
1468 return json_throw_parse_error(l, json, "comma or object end", &token);
1469
1470 json_next_token(json, &token);
1471 }
1472 return 1;
1473}
1474
1475/* Handle the array context */
1476static int json_parse_array_context(lua_State *l, json_parse_t *json)

Callers 1

json_process_valueFunction · 0.85

Calls 7

json_decode_descendFunction · 0.85
json_next_tokenFunction · 0.85
json_decode_ascendFunction · 0.85
json_throw_parse_errorFunction · 0.85
lua_pushlstringFunction · 0.85
json_process_valueFunction · 0.85
lua_rawsetFunction · 0.85

Tested by

no test coverage detected