lua-users home
lua-l archive

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


There is a well known weakness in the check of the length of tables, or
at least there is no real and safe check of the length at all. 
In a posting I found the description for that. "This is not a bug, just
confusing behaviour of the length operator (which should be called "give
me a free table index minus one "-operator instead)" Source: Subject:
Re: The table length is not correct, From: Kristofer Karlsson
<kristofer.karlsson@...>, Date: Fri, 6 Mar 2009 13:30:51 +0100

________________________________________________________________________
And the Lua manual describes the length function as follows:

The length of a table t is defined to be any integer index n such that
t[n] is not nil and t[n+1] is nil; moreover, if t[1] is nil, n can be
zero. For a regular array, with non-nil values from 1 to a given n, its
length is exactly that n, the index of its last value. If the array has
"holes" (that is, nil values between other non-nil values), then #t can
be any of the indices that directly precedes a nil value (that is, it
may consider any such nil value as the end of the array). 

Is`nt it possible to tackle that problem in the new version? I do not
know how severe such a change would be for the Lua kernel.

Regards BB