Jump to content
  • Advertisement
Sign in to follow this  
Zane528

Lua Object Scripts

This topic is 4008 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

I am trying to extend my classes through scripting. I create my objects in Lua and then assign them a script. I can't find a way to load a script and connect it to that object, so in c++ I can call that objects scripted function. I can do it globally by loading the script into a table and then calling the function in that table. What I want to do is connect that table to the full userdata so each object can have it's own script, and can be easily called from c++.

Share this post


Link to post
Share on other sites
Advertisement
The usual way for a C++ object to hold onto a Lua object is through the Lua registry, which see the manual. If you're using a binding system like LuaBind or SWIG, though, the preferred method may be different.

Share this post


Link to post
Share on other sites
Seems very confusing to me. Could you explain or give an example of what you want to do ? If you create your objects in Lua as you said, why can't you assign them a lua file ?

myObject1 = CreateMyUserData("myObject1Script.lua")
myObject2 = CreateMyUserData("myObject2Script.lua")

The C function CreateMyUserData check the filename of the script and keep it in a string to call the script later.

Share this post


Link to post
Share on other sites
I'm using lunar for the binding. Right now I am keeping the script in a string and call it when I need to. The problem with this is that I can't save any of the variables in the script to use later on. If I load it into a table in the object, then I should be able to access them until the object dies.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!