Behavior of assignment with user data in Lua

Started by
0 comments, last by Laval B 10 years, 6 months ago

Hello everyone.

I have created and exposed a C++ class to Lua as a user data. Meta function __gc has been written and it works fine. I can make multiple instances (using the new function) of that object in a script and call their methods and they work. However, the behavior of the assignment is not what i need it to be. It looks like variables in scripts are references to objects in the virtual machine. Therefore, if i write a statement like

x = y

in a script where x and y are both user data of the same type, x becomes a reference to the same object as y. Is there a way to override this behavior ? I know it is possible to override comparisons by defining __eq meta function (ans __le, etc).

Is it also possible to prevent assignment where it doesn't make sense ?

We think in generalities, but we live in details.
- Alfred North Whitehead
Advertisement

Nevermind, it's a stupid question. I'll just implement a clone method.

We think in generalities, but we live in details.
- Alfred North Whitehead

This topic is closed to new replies.

Advertisement