Luabind help with exposing classes

Started by
0 comments, last by rocklobster 12 years ago
Hi,

I've recently begun using Lua and Luabind to interface with my game engine. However, i've ran into a couple of problems. I'm very new to luabind and lua and i really dont know how to debug. What i've been doing currently is just setting break points in the actual c++ code to see if lua is calling it when it reaches that statement. So anyway, on to my actual question.

I've got a derived class that is templated (the base class is not) and in luabind you have to specify a specific implementation of the template to bind it. Which i have done. In C++ it would be like this...

TemplateFactory<Button> buttonFactory = new TemplateFactory<Button>();

TemplateFactory derives from BaseFactory and this is how it is used. We then usually pass these factories into our main UIFactory which internally tracks the different types of objects to produce from the factories its given.

class UIFactory
{
void addComponentFactory(string name, BaseFactory* factory)
};
...
UIFactory* factory = new UIFactory();
factory.addComponentFactory("Button", buttonFactory);


Now in luabind i've exposed UIFactory class and created an object of that, and i've also created an object of the template factory like so...


luabind::module(state)
[
class_<TemplateFactory<Button> >("ButtonFactory")
.def(constructor<>())
];
luabind::module(state)
[
class_<UIFactory>("UIFactory")
.def("AddFactory", &addComponentFactory)
];
and in lua...
uiFactory = UIFactory()
buttonFactory = ButtonFactory()
uiFactory:AddFactory("Button", buttonFactory) // this is the problem


So i'm not sure if i need to expose BaseFactory or be exposing TemplateFactory differently. I've been looking through rasterbar documentation but havn't found a solution and there really isnt much out there on luabind. It would help a great deal if someone could help me fine the problem.

- rocklobster
Advertisement
Solved it by exposing the base class to lua and indicating that the template factory was derived

luabind::module(state)
[
luabind::class_<BaseFactory>("BaseFactory")
];
luabind::module(state)
[
luabind::class<TemplateFactory<Button>, BaseFactory>("ButtonFactory")
.def(constructor<>())
]

This topic is closed to new replies.

Advertisement