Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Luabind help with exposing classes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 rocklobster   Members   -  Reputation: 415

Like
0Likes
Like

Posted 10 April 2012 - 12:22 AM

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

Sponsor:

#2 rocklobster   Members   -  Reputation: 415

Like
0Likes
Like

Posted 10 April 2012 - 02:22 AM

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<>())
]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS