mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-04 02:41:19 +00:00
[Lua] add __len metafunction for readonly objects
This commit is contained in:
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…
Reference in New Issue
Block a user