[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: AW: Assignment of tables?
- From: Robert Anderberg <lua@...>
- Date: Sun, 16 Nov 2003 20:18:39 +0100
there are so many special cases that it's much easier to write your own
function eg:
function copyTable(_table)
local newTable = {}
for key,value in pairs(_table) do
newTable[key] = value
end
return newTable
end
On Sunday 16 November 2003 7:14 pm, Jason P wrote:
> > > lets say I need to reset a table to some older state. Will this work?:
> > > MyTable = OlderTable;
> > > and what would happen to C refs which are attached to 'MyTable'?
> >
> >With the assignment you only assign a reference to the table.
> >After this instruction, both MyTable and OlderTable refer to the
> >same structure. If you change one, the change is visible from the
> >other, too.
> >
> >If MyTable was the only reference to that table, before you re-
> >assigned it, the table still stays in memory and will sometime
> >be collected by the garbage collector (at least at program exit).
> >
> >If there are other references left, nothing will happen to the table.
>
> ok, I understand. So there are no easy copytable() type abilities inside
> lua's base lib?
>
> _________________________________________________________________
> Send a QuickGreet with MSN Messenger
> http://www.msnmessenger-download.com/tracking/cdp_games