[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: copying userdata objects?
- From: "J. Perkins" <jason@...>
- Date: Mon, 01 Apr 2002 09:30:49 -0500
I have added a couple of 3D object types (vector, matrix,
quaternion) to Lua as userdata objects. The default behavior of a
statement like:
vector2 = vector1
is to set both values to reference the same userdata object. But I
would like my math objects to behave like the simple data types, in
that assignment makes a *copy* of the object, and changing vector2
would have no effect on vector1. Is there an easy way to accomplish
this in Lua? There doesn't seem to be an assignment tag method. The
only way I can think to make it work is to create a new userdata
object on every call to "settable", but that would generate a lot of
garbage. If I could detect the assignment, I could at least use a
refcount scheme to only duplicate the necessary objects.
Thanks,
Jason