lua-users home
lua-l archive

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

> I am very pleased my posting on table.insert and table.remove:
> has been acted upon, however examining the rc2 source code, should not the
> upper boundary for table.remove be  'aux_getn()' rather than 'aux_getn()+1'?
> Mostly it will not matter since that value will be nil anyway, but it could
> cause problems in some scenarios where there is a __len metamethod.

Consider this somewhat common idiom:

   -- print and remove all elements from a list 't':
   while true do
     local e = table.remove(t, 1)
     if e == nil then break end

That code would break if 'table.remove' did not accept len+1.

-- Roberto