MCPcopy Create free account
hub / github.com/DavidColson/Polybox / ParseTextTable

Function ParseTextTable

source/serialization.cpp:449–533  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

447// ***********************************************************************
448
449void ParseTextTable(lua_State* L, Scan::ScanningState& scan, bool isMetadata = false) {
450 lua_newtable(L);
451 i32 arrayIndex = 1;
452
453 // While loop over each table element
454 while (!Scan::IsAtEnd(scan)) {
455 Scan::AdvanceOverWhitespace(scan);
456 char c = Scan::Advance(scan);
457
458 // Identifier
459 if (Scan::IsAlpha(c)) {
460 char* start = scan.pCurrent - 1;
461 while (Scan::IsAlphaNumeric(Scan::Peek(scan)))
462 Scan::Advance(scan);
463
464 String identifier = CopyCStringRange(start, scan.pCurrent, g_pArenaFrame);
465
466 if (identifier == "true") {
467 lua_pushboolean(L, 1);
468 lua_rawseti(L, -2, arrayIndex);
469 arrayIndex++;
470 continue;
471 }
472 else if (identifier == "false") {
473 lua_pushboolean(L, 0);
474 lua_rawseti(L, -2, arrayIndex);
475 arrayIndex++;
476 continue;
477 }
478 else if (identifier == "userdata") {
479 if (Scan::Peek(scan) == '(') {
480 ParseUserData(L, scan);
481 lua_rawseti(L, -2, arrayIndex);
482 arrayIndex++;
483 continue;
484 }
485 }
486
487 if (!Scan::Match(scan, '=')) {
488 luaL_error(L, "Expected '=' after table key", i64(scan.pCurrent - scan.pTextStart));
489 }
490
491 ParseTextValue(L, scan);
492 lua_setfield(L, -2, identifier.pData);
493 continue;
494 }
495
496 // Is value
497 if (Scan::IsDigit(c) || c == '-' || c == '.' || c == '\'' || c == '"') {
498 scan.pCurrent--;
499 ParseTextValue(L, scan);
500 lua_rawseti(L, -2, arrayIndex);
501 arrayIndex++;
502 continue;
503 }
504
505 // Is string or number identifier
506 if (c == '[') {

Callers 2

ParseTextValueFunction · 0.85
DeserializeFunction · 0.85

Calls 2

ParseUserDataFunction · 0.85
ParseTextValueFunction · 0.85

Tested by

no test coverage detected