[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: use of gettop to change functionality
- From: Axel Kittenberger <axkibe@...>
- Date: Tue, 1 Mar 2011 23:10:46 +0100
>> 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()