[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua life after integers
- From: Andrew Starks <andrew.starks@...>
- Date: Wed, 10 Dec 2014 14:19:05 -0600
On Wed, Dec 10, 2014 at 1:55 PM, Tim Hill <drtimhill@gmail.com> wrote:
> 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.)
I'm not quite following you.
Are you saying that if __len is not defined, 5.3 will always stop at
the first `nil` value, regardless of `#t`'s value? And to read into
that, if __len *is* defined, it will respect the length?
I'm still on an alpha and I think that my version has the now reverted
behavior, am I correct?
```
-- Lua 5.3 alpha 3
local t = {'foo', 'bar', 'baz', 'doomed', 'test'}
t[4] = nil
print('length of t', #t)
-->length of t 5
for i = 1, #t do
print("value is", t[i])
end
--[[-->
value is foo
value is bar
value is baz
value is nil
value is test
--]]
t[#t + 1] = 'last'
print('length of t', #t)
-->length of t 3
for i = 1, #t do
print("value is", t[i])
end
--[[
value is foo
value is bar
value is baz
--]]
```
-Andrew
- References:
- Lua life after integers, Tuom Larsen
- 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