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

Method jcontResize

source/core/StarLua.cpp:1541–1559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1539}
1540
1541void LuaDetail::jcontResize(LuaTable const& table, size_t targetSize) {
1542 if (auto mt = table.getMetatable()) {
1543 if (auto nils = mt->rawGet<Maybe<LuaTable>>("__nils")) {
1544 nils->iterate([&](LuaValue const& key, LuaValue const&) {
1545 auto i = asInteger(key);
1546 if (i && *i > 0 && (size_t)*i > targetSize)
1547 nils->rawSet(key, LuaNil);
1548 });
1549 }
1550 }
1551
1552 table.iterate([&](LuaValue const& key, LuaValue const&) {
1553 auto i = asInteger(key);
1554 if (i && *i > 0 && (size_t)*i > targetSize)
1555 table.rawSet(key, LuaNil);
1556 });
1557
1558 table.set(targetSize, table.get(targetSize));
1559}
1560
1561Maybe<LuaInt> LuaDetail::asInteger(LuaValue const& v) {
1562 if (v.is<LuaInt>())

Callers

nothing calls this directly

Calls 5

getMetatableMethod · 0.80
iterateMethod · 0.80
rawSetMethod · 0.80
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected