| 1503 | } |
| 1504 | |
| 1505 | size_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 | |
| 1541 | void LuaDetail::jcontResize(LuaTable const& table, size_t targetSize) { |
| 1542 | if (auto mt = table.getMetatable()) { |
nothing calls this directly
no test coverage detected