lua-users home
lua-l archive

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


Lua list <lua@bazar2.conectiva.com.br> writes:
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.

True, I guess I was thinking more of a copy constructor than an overloaded operator.

I guess a var1:CopyFrom() (or :Assign()) really is the best you can do then, sorry for the misinterpretation.

Having said that, personally, I like the clarity of this over having to think every time I do A = B whether or not this is:
- Make A refer to the same object that B refers to
- Create a new object from B and assign a reference to it to A, overwriting the reference stored in A before.
- A continues to refer to the same object as before but has had some of its internal fields tweaked such that they've been copied from B.

Worse yet, if a metamethod were defined to do something like this, the rules could vary depending on the types of A and B.

James.