[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Check for ipairs() compat mode
- From: Dirk Laurie <dirk.laurie@...>
- Date: Thu, 19 Jul 2018 13:09:08 +0200
2018-07-19 11:33 GMT+02:00 <tobias@justdreams.de>:
>
> Quoting Dirk Laurie <dirk.laurie@gmail.com>:
>
>> 2018-07-19 1:52 GMT+02:00 <tobias@justdreams.de>:
>>
>>
>>> I guess I can shorten it to the minimum but it's still clumsy:
>>>
>>> local t = setmetatable( {},{__ipairs=function(tbl) return function()
>>> return
>>> nil,nil,true end,tbl,0 end})
>>>
>>> local a,b,c = ipairs(t)
>>> local _,_,_isCompat = a(b,c)
>>
>>
>> I replied to the first post before reading this one. Here you do have an
>> example. This example runs perfectly for me in both Lua 5.3 and 5.4.
>>
>> But maybe it is a simpler case than the one on which you observed
>> the offending behaviour.
>
>
> When running that code in 5.4, _isCompat==true for you?
Yes. But I see now, my /usr/local/lua5.4 is shadowed by $HOME/bin/lua5.4.
which was compiled from a github clone on 22 January. I should have noticed
it from the version line, whichs says "1994-2017".
Using /usr/local/lua5.4, _isCompat==nil.
A simple test is:
if ipairs(t) == ipairs{} then
print"Either tbl has no __ipairs metamethod or it is not recognized"
end