lua-users home
lua-l archive

Re: metamethods for assignment and type conversion

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


Lua wrote:
*Adrien de Croy <adrien@qbik.com <mailto:adrien@qbik.com>> writes:
*In which case, separate functions will need to be written to deep-copy
objects... you end up with code like
deepcopy(var1, var2);
or maybe
var1.Assign(var2);
instead of
var1 = var2;
My thought after reading this thread was:
var1 = var2:Duplicate(); or
var1 = var2:Copy()
neither of these affect the C++ object that is wrapped by var1, var1 instead gets a new pointer to wrap (being a copy), and the old one is garbage-collected. If you want to modify the pointer that var1 wraps, then var1 needs to be involved in the function that does the assignment.
Regards
Adrien
I do this in some of my Lua code and it works pretty well. I find it makes it pretty easy to tell when a new resource is allocated vs. simply referenced in a new way.
Of course what's clear to me, may be mud to others...
James.
--
Adrien de Croy - WinGate Proxy Server - http://www.wingate.com

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