• Advertisement
Sign in to follow this  

Luabind help with exposing classes

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

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...

[code]TemplateFactory<Button> buttonFactory = new TemplateFactory<Button>();[/code]

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.

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

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...


[code]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[/code]

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

Share this post


Link to post
Share on other sites
Advertisement
Solved it by exposing the base class to lua and indicating that the template factory was derived

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement