lua-users home
lua-l archive

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


I do not understand you question. but try this

t={}
row=1
table.insert(t,row)
row=2
table.insert(t,row)
row=3
table.insert(t,row)
tanle.foreach(t,print)

outputs

1       1
2       2
3       3

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