[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua life after integers
- From: Sean Conner <sean@...>
- Date: Wed, 10 Dec 2014 15:06:01 -0500
It was thus said that the Great Tim Hill once stated:
>
> > On Dec 10, 2014, at 9:32 AM, Sean Conner <sean@conman.org> wrote:
> >
> > If that were true, then ipairs() would be removed as you can always do:
> >
> > for i = 1 , #t do ... end
>
> As has been noted before, this does not have the same behavior as ipairs()
> if the table is not a valid sequence. (Earlier betas of 5.3 did have this
> behavior, but it has been reverted to stop the iteration at the first nil
> value, which is not necessarily at #t+1 for non-sequences.)
Hmm ... I just tried the following in Lua 5.2 and it worked:
mt =
{
__len = function(s) return 100 end,
__index = function(s,k) return nil end,
}
x = setmetatable({},mt)
for i = 1 , #x do
print(i,x[i])
end
But yes, if that metatable isn't there, then the loop will print nothing.
-spc
- References:
- Re: Lua life after integers, Hisham
- Re: Lua life after integers, Rena
- Re: Lua life after integers, Luiz Henrique de Figueiredo
- Re: Lua life after integers, Rena
- Re: Lua life after integers, Luiz Henrique de Figueiredo
- Re: Lua life after integers, Rena
- Re: Lua life after integers, Dirk Laurie
- Re: Lua life after integers, Andrew Starks
- Re: Lua life after integers, Sean Conner
- Re: Lua life after integers, Tim Hill