Hi everybody,
I'm using luabind to bind c++/lua. I went through their tutorials. But I'm a little lost because I can't figure out where architecturally put the binding code.
Does anybody have any experience with this that they can share?
Where to put lua/c++ binding code?
-
- Greenskin
- Posts: 115
- Joined: Thu Jun 09, 2011 5:41 am
- Location: Melbourne, Australia
- x 5
-
- Ogre Magi
- Posts: 1120
- Joined: Wed Nov 15, 2006 7:41 pm
- Location: Finland
- x 5
Re: Where to put lua/c++ binding code?
Hmm... so what's the problem exactly...
Personally I've created a LuaVirtualMachine class which holds the necessary code to boot tolua++ (notice I do not use luabind, but this should not matter in this) and to set up the necessary connections to some of my c++ variables that I want to create on the c++ side and then pass on to Lua for manipulation. And I pass a boost::shared_ptr of that LuaVirtualMachine class to subsystems. So the main function of the program instantiates an object of this class (as one of the first things the program does - I use Lua scripts as settings files for my application), and I then pass that object to subsystems.
So this is one way to do it. I don't think there is too much difficulty here, you just give access to your LuaVirtualMachine class to all subsystems that need to use it. You can of course instantiate more than one Lua engine if you want to break it down further, but I've not done this in my application as I think it's enough to just clear all data that is not needed any more out of the running Lua at some points so you don't leave unnecessary clutter for the rest of the duration of run of the application.
Personally I've created a LuaVirtualMachine class which holds the necessary code to boot tolua++ (notice I do not use luabind, but this should not matter in this) and to set up the necessary connections to some of my c++ variables that I want to create on the c++ side and then pass on to Lua for manipulation. And I pass a boost::shared_ptr of that LuaVirtualMachine class to subsystems. So the main function of the program instantiates an object of this class (as one of the first things the program does - I use Lua scripts as settings files for my application), and I then pass that object to subsystems.
So this is one way to do it. I don't think there is too much difficulty here, you just give access to your LuaVirtualMachine class to all subsystems that need to use it. You can of course instantiate more than one Lua engine if you want to break it down further, but I've not done this in my application as I think it's enough to just clear all data that is not needed any more out of the running Lua at some points so you don't leave unnecessary clutter for the rest of the duration of run of the application.
-
- Greenskin
- Posts: 115
- Joined: Thu Jun 09, 2011 5:41 am
- Location: Melbourne, Australia
- x 5
Re: Where to put lua/c++ binding code?
Sorry if I was vague but you've got the right idea.reptor wrote:Hmm... so what's the problem exactly...
So your LuaVirtualMachine class, does it have includes for every class you want to expose to lua? And also how do you expose private vars?