lua-users home
lua-l archive

Re: Lua, LuaJIT2 and differences with the length operator

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


On Tue, Jan 4, 2011 at 3:41 PM, Norbert Kiesel <nkiesel@tbdnetworks.com> wrote:
> 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 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.
>>
> Using "#t == table.maxn(t)" as a test for no-hole tables does not work
I know that, but I never said it did. My point was, if you're worried
about using #t because you expect hole-containing input, then don't
use #t. Using table.maxn() instead of #t is no more expensive than
looking for holes in the first place. (That's was what I meant by
"call table.maxn() instead".)
Greg F

AltStyle によって変換されたページ (->オリジナル) /