[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua, LuaJIT2 and differences with the length operator
- From: Norbert Kiesel <nkiesel@...>
- Date: Tue, 04 Jan 2011 12:41:51 -0800
On Tue, 2011-01-04 at 13:18 -0500, Greg Falcon 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.
>
> Greg F
>
Using "#t == table.maxn(t)" as a test for no-hole tables does not work
(and I did not expect it to work given the definitions of #t and
table.maxn(t), just want to make sure this wrong advise does not stay
undisputed in the archives):
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> t={1,nil,3}
> =#t
3
> =table.maxn(t)
3
</nk>
- 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