[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 Length Operator and tables (bug?)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 18 Apr 2012 19:11:59 -0300
> 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
- References:
- Re: Lua 5.2 Length Operator and tables (bug?), Joseph Manning
- Re: Lua 5.2 Length Operator and tables (bug?), Coda Highland
- Re: Lua 5.2 Length Operator and tables (bug?), Dirk Laurie
- Re: Lua 5.2 Length Operator and tables (bug?), Coda Highland
- Re: Lua 5.2 Length Operator and tables (bug?), joao lobato
- Re: Lua 5.2 Length Operator and tables (bug?), Coda Highland
- Re: Lua 5.2 Length Operator and tables (bug?), joao lobato
- Re: Lua 5.2 Length Operator and tables (bug?), Eduardo Ochs
- Re: Lua 5.2 Length Operator and tables (bug?), Roberto Ierusalimschy
- Re: Lua 5.2 Length Operator and tables (bug?), Petite Abeille