[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Check for ipairs() compat mode
- From: tobias@...
- Date: Thu, 19 Jul 2018 01:35:11 +0200
Hi,
Lua 5.3 had an ipairs() Compat which seemed enabled by default. 5.4
has done away with it.
I have a implementation of an ordered hash table where I can
for i,v,k in ipairs(o) do
print(i,v,k) -- k is the key for value at index i
end
The newer implementation of ipairs() does not honour if __ipairs
returns more than 2
values. Not a big issue but it would be nice if we can test for it.
Here is my (rather
verbose) implementation:
t = setmetatable( {0,1,2,3,4,5,6,7,8,9},
{
__ipairs = function( tbl )
local idx = 0
return function( key )
idx=idx+1;
if tbl[idx] then
return idx, tbl[idx], 'foo'
end end, tbl, 0
end
}
)
a,b,c = ipairs(t)
x,y,z = a(b,c)
if 'foo' == z then IPAIRS_IS_COMPAT end
Is there an easier way to test for it?
Thanks,
--tobbik