[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua, LuaJIT2 and differences with the length operator
- From: Peter Cawley <lua@...>
- Date: Wed, 29 Dec 2010 15:22:05 +0000
On Wed, Dec 29, 2010 at 3:18 PM, Daniele Alessandri
> Which one is right? I guess Lua, even if
> http://www.lua.org/manual/5.1/manual.html#2.5.5 states that "If the
> array has holes (that is, nil values between other non-nil values),
> then #t can be any of the indices that directly precedes a nil value
> (that is, it may consider any such nil value as the end of the
> I would expect at least the same behavior, or am I just doing it wrong
> by trying to rely on the current one showed by Lua 5.1?
They are both right. As the manual states, in cases like these, there
are multiple "right" lengths, and implementations are free to give you
any of the "right" lengths. Hence relying on all implementations
giving the same result is bad practice, as this isn't guaranteed.