[Lua] add __len metafunction for readonly objects

macos_ci_fix
Petr Mikheev 1 year ago
parent c5789b5543
commit f86a45d60a

@ -246,6 +246,9 @@ namespace LuaUtil
local nextFn, t, firstKey = ipairs(getmetatable(v).t)
return function(_, k) return nextFn(t, k) end, v, firstKey
end
function lenForReadOnly(v)
return #getmetatable(v).t
end
local function nextForArray(array, index)
index = (index or 0) + 1
if index <= #array then
@ -300,6 +303,7 @@ namespace LuaUtil
meta["__index"] = table;
meta["__pairs"] = lua["pairsForReadOnly"];
meta["__ipairs"] = lua["ipairsForReadOnly"];
meta["__len"] = lua["lenForReadOnly"];
lua_newuserdata(luaState, 0);
sol::stack::push(luaState, meta);

Loading…
Cancel
Save