Jump to content
  • Advertisement
Sign in to follow this  
Laval B

Behavior of assignment with user data in Lua

This topic is 2105 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!