lua-users home
lua-l archive

Re: Pass vars value not reference to table.insert

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


or try
rows={}
local result =fetchrow()
while result do
 rows[#rows+1] = result
 result =fetchrow()
end
Or am I missing the point of your question?
db
On 1/27/07, Jan Schütze <JanS@dracoblue.de> wrote:
Hello,
The following pseudo code won't add every 3 rows to the table rows,
because row is a variable so rows would contain one item, and 3 pointers
to it.
 rows={}
 local row = fetchRow()
 while (row) do
 table.insert(rows,row)
 row = fetchRow()
 end
Is there any way to add the 'row'-values content and not a pointer to it?
Currently I use:
 rows={}
 local row = fetchRow()
 while (row) do
 local row2={}
 for key,value in pairs(row) do
 row2[key]=value
 end
 table.insert(rows,row2)
 row = fetchRow()
 end
But I am sure this is easier in lua.
Kind regards,
 Jan (DracoBlue)
--------------------------
 http://dracoblue.net

AltStyle によって変換されたページ (->オリジナル) /