Question

I've been learning Luabind recently with the intention of integrating into our software. I've run into a couple of problems and i've been looking at the Rasterbar Software documentation of Luabind and have not been able to solve it. Basically, i'm exposing a function which takes a string and an abstract base class as parameters. Firstly, i'm not sure if i'm going about this the correct way or there maybe some special treatment required in lua for this to work. Anyway, here's the code

class UIFactory
{
    void addComponentFactory(std::string name, BaseFactory* factory);
}

BaseFactory is an abstract base class that returns a UIComponent (button, text etc) and we have derived factory called TemplateFactory which basically can be instantiated like so..

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

Then we would pass these to the UIFactory in c++ like this...

uiFactory.addComponentFactory("Buttons", buttonFactory);

in luabind...

module(state)
[
    class_<UIFactory>("UIFactory")
    .def(constructor<>())
    .def("AddFactory", &UIFactory::addComponentFactory)
];

and in lua...

uiFactory = UIFactory()

buttonFactory = ButtonFactory()

uiFactory:AddFactory("Button", buttonFactory)

That last line does not execute, i've checked that the button factory and ui factory were being created and they were. Is there anthing i'm missing?

Help is greatly appreciated.

Was it helpful?

Solution

Turns out I needed to expose the base class to lua and also indicate that buttonFactory was derived

luabind::module(state)
[
    luabind::class_<BaseFactory>("BaseFactory")
];

luabind::module(state)
[ 
    luabind::class<TemplateFactory<Button>, BaseFactory>("ButtonFactory")
    .def(constructor<>())
]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top