Sign in to follow this  

Behavior of assignment with user data in Lua

This topic is 1520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

 

Share this post


Link to post
Share on other sites

This topic is 1520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this