lua-users home
lua-l archive

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

> I would rather prefer:
>  if type(k) == 'number' and math.floor(k) == k then
>      if 1 <= k and k <= n then
>         i = i + 1
>      else
>         return false
>      end
>   end
> This way, table's hash part as well as numeric keys with fractional
> part like 3.33 (which belong to hash part) are excluded from testing.

This is a matter of taste. You may also move the '1 <= k' test to
the outer if, to allow negative indices which also do not interfere
with lists. I particularly do not see much use for such indices (both
negative and fractional), and so it seems simpler to assume that all
numeric indices are in the list.

-- Roberto