lua-users home
lua-l archive

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


> FWIW, here is an alternative implementation:
> 
> local function is_seq( aTable )
>   for aKey in pairs( aTable ) do
>     if not( type( aKey ) == 'number' and aKey > 0 and aKey == math.floor( aKey ) and aTable[ math.max( aKey - 1, 1 ) ] ~= nil ) then
>       return false
>     end
>   end
> 
>   return true
> end

This one does not follow the definition in the manual (where, for
instance, non-number keys do not interfere with sequences). But the
trick 'aKey - 1' is cute :)

-- Roberto