|
HiI was talking more about where you are using Lua to manipulate objects that live in the host.
In those cases, assigning a userdata variable in lua to another one is no use, since it only sets the contained pointer to point to the other one. the copy required in this case can only be done by the host application, and therefore needs to be called back on it.
It's the difference between copying a pointer, and copying the object pointed to by the pointer.
Aaron Brown wrote:
that won't work either, since nothing goes up the stack to set whatever is wrapped by object1. It would need to be something that passes up object1 up the stack as well as object2 so that the handler could do the magic. E.g.The part about assignment being blocked still would, though. As you said, __assign could be used judiciously, but why not just do: object1 = deepcopy(object2)
if you have userdata1 and userdata2, userdata1 wraps 0x04000001 and userdata2 wraps 0x04000002 then once you do
userdata1 = userdata2 in lua, then both wrap the same pointer. What I want is that the pointers are not touched, so they both wrap the same pointer they had before, but the object pointed to by the userdata2 pointer has been deep-copied into the pointer wrapped by userdata1.
With tables it's a similar concept. The table wraps an object. We want to manipulate the wrapped C++ object using Lua, not manipulate the lua table. We're using a table interface to do it with metamethods.
hmmmm ok. I guess it would be a bit harder to do then since it won't be channeled through one point :)and leave the assignment syntax to do what it normally does?but it doesn't really make that much sense that lua exposes all the other operators except assignment.Unlike in some other languages, in Lua assignment is not an operator, it's a statement. (And, for that matter, there are no metamethods for the "and", "or", & "not" operators.)
I've already coded part of the __cast metamethod. It's working very well, I'm able to automatically convert tables into strings with a callback now.Good. -- Aaron http://arundelo.com/ _________________________________________________________________More photos, more messages, more storage—get 2GB with Windows Live Hotmail. http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507
-- Adrien de Croy - WinGate Proxy Server - http://www.wingate.com