lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 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