lua-users home
lua-l archive

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


On Tue, Jan 4, 2011 at 08:41, Dirk Laurie <dpl@sun.ac.za> wrote:
> On Tue, Jan 04, 2011 at 03:18:29PM +0200, Leo Razoumov wrote:
>> Lua provides no good way to test whether a given array has holes or
>> not.
> Not Lua's job.  Your job.
>
> You, as programmer, make a conscious decision as to whether your
> arrays are allowed to contain holes.  If so, you don't rely on
> the default #, table.insert, table.remove.
>

table.insert does not help. Please, read the manual.

-- From the Lua 5.1.4 manual
table.insert (table, [pos,] value)
Inserts element value at position pos in table, shifting up other
elements to open space, if necessary. The default value for pos is
n+1, where n is the length of the table (see §2.5.5), so that a call
table.insert(t,x) inserts x at the end of table t.

table.insert uses the same #len operator (aux_getn to be exact) and
will gladly insert your new value into the first available hole.

>Trying very hard, this early 2011, to be a nice person,
>Dirk

Try harder!

--Leo--