[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua, LuaJIT2 and differences with the length operator
- From: Sam Roberts <vieuxtech@...>
- Date: Tue, 4 Jan 2011 11:00:48 -0800
On Tue, Jan 4, 2011 at 10:18 AM, Greg Falcon <veloso@verylowsodium.com> wrote:
> On Tue, Jan 4, 2011 at 1:02 PM, Leo Razoumov <slonik.az@gmail.com> wrote:
>> I am fine with the way #t operator is defined. It is logical and
>> consistent. My problem is different. I cannot see a good way to tell
>> when it is safe to trust #t and when not (longing for table.has_holes
>> test)
>
> The only way to test if a table has holes is to walk it. So if you
> just want to know if you can trust the answer of #t, call table.maxn()
> instead. It takes just as long as table.has_holes() would, and it
> gives you the answer you're looking for as well.
table.maxn() will find non-integral numbers:
> t={[1]=1,[2.2]=2}
> = #t
1
> = table.maxn(t)
2.2
You'd need a table.maxi(), something similar to what Roberto posted above.
Cheers,
Sam
- 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, Tony Finch
- Re: Lua, LuaJIT2 and differences with the length operator, Leo Razoumov
- Re: Lua, LuaJIT2 and differences with the length operator, Greg Falcon