MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / jcontSize

Method jcontSize

source/core/StarLua.cpp:1505–1539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1503}
1504
1505size_t LuaDetail::jcontSize(LuaTable const& table) {
1506 size_t elemCount = 0;
1507 size_t highestIndex = 0;
1508 bool hintList = false;
1509
1510 if (auto mt = table.getMetatable()) {
1511 if (mt->rawGet<Maybe<int>>("__typehint") == 1)
1512 hintList = true;
1513
1514 if (auto nils = mt->rawGet<Maybe<LuaTable>>("__nils")) {
1515 nils->iterate([&](LuaValue const& key, LuaValue const&) {
1516 auto i = asInteger(key);
1517 if (i && *i >= 0)
1518 highestIndex = max<int>(*i, highestIndex);
1519 else
1520 hintList = false;
1521 ++elemCount;
1522 });
1523 }
1524 }
1525
1526 table.iterate([&](LuaValue const& key, LuaValue const&) {
1527 auto i = asInteger(key);
1528 if (i && *i >= 0)
1529 highestIndex = max<int>(*i, highestIndex);
1530 else
1531 hintList = false;
1532 ++elemCount;
1533 });
1534
1535 if (hintList)
1536 return highestIndex;
1537 else
1538 return elemCount;
1539}
1540
1541void LuaDetail::jcontResize(LuaTable const& table, size_t targetSize) {
1542 if (auto mt = table.getMetatable()) {

Callers

nothing calls this directly

Calls 2

getMetatableMethod · 0.80
iterateMethod · 0.80

Tested by

no test coverage detected