lua-users home
lua-l archive

Pass vars value not reference to table.insert

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


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 によって変換されたページ (->オリジナル) /