[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua, LuaJIT2 and differences with the length operator
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 5 Jan 2011 10:07:24 -0200
> Should that not better be
>
> if type(k) == 'number' and math.floor(k) == k and 1 <= k and k <= n then
> i = i + 1
> else
> return false
> end
>
> i.e. always return false if we find a non-number key, given the "if t[1]
> is nil, #t can be zero" caveat in the definition of #t?
It is very common in Lua to have a list together with non-numeric keys,
like here:
line = {{3, 0}, {10, 24.3}, {27, 32.1}, {49, -45}; color="red"}
There is no reason to prevent '#' being applied on these lists. (The
caveat has nothing to do with non-numeric keys.)
-- Roberto
- References:
- Re: Lua, LuaJIT2 and differences with the length operator, Leo Razoumov
- Re: Lua, LuaJIT2 and differences with the length operator, Dirk Laurie
- Re: Lua, LuaJIT2 and differences with the length operator, Leo Razoumov
- Re: Lua, LuaJIT2 and differences with the length operator, Roberto Ierusalimschy
- Re: Lua, LuaJIT2 and differences with the length operator, Norbert Kiesel