Lua Object Scripts

Started by
2 comments, last by Zane528 16 years, 5 months ago
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++.
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.
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.
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.

This topic is closed to new replies.

Advertisement