lua-users home
lua-l archive

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


>>  mytableinsert = function (T, ...)
>>      local objects = table.pack(...)
>>      for i=1,n do
>>        T.n = T.n + 1
>>        T[n] = objects[i]
>>      end
>>      return T
>>    end
>
> I really hope programs like this do not become common. Making a new
> garbage table on every insert?! This is why I advocated having
> table.pack accept a table argument...

Same functionality, no table created by pack.

function myinsert(T, ...)
   local n = select('#', ...)
   for i=1,n do
     T.n = T.n + 1
     T[n] = (select(i, ...))
   end
   return T
end

On a side node, I would call the size field of the table ['#'] to
match the syntax of select()