Question

I am writing a game engine in c++ which will provide Lua scripting ( for which wrapping I am using Luabind ) and I am having some problems to bind overloaded functions. Namely: I have am overloaded function :

void setGlobalPosition(const Vec3& position);

void setGlobalPosition(Real x, Real y, Real z);

And I would like to expose both of these to lua. obviously this is wrong:

luabind::module(L)[ luabind::class_<Critter::Body>("Body") .def("setGlobalPosition", &Critter::Body::setGlobalPosition ) ];

I have found a way to do it on this site http://www.codeproject.com/KB/graphics/luabindLuaAndOgre3d.aspx?msg=3376320 (very good tutorial for Luabind - I strongly recommend it) like this :

luabind::module(L)[ luabind::class_<Critter::Body>("Body") .def("setGlobalPosition", (void( Critter::Body::*)(const Vector3&))Critter::Body::setGlobalPosition ) ];

but it also gives me errors (I can attach them if somebody is interested).

I have also tried .def("setGlobalPosition", Critter::Body::setGlobalPosition<Vector3> ) but still errors.

Any ideas how can I do it ?


EDIT: Ok, I have found a way to do it like that:

.def("setGlobalPosition", ( void(Critter::Body::*)(Vector3) ) &Critter::Body::setGlobalPosition )

from the luabind documentation but I get errors (the first one):

error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'void (__thiscall Critter::Body::* )(Ogre::Vector3)'

but anyway the problem arises cuz this function is inherited (it comes from NxOgre::Actor:: so I don't that the right approach anyway


EDIT 2 :

I have just tried to bind the version of function with 3 floats as parameters and ... surprisingly everything compiles just fine but the version with vector3 does not.... :(

this is what I have used to implement 3 float function:

.def("setGlobalPosition", ( void(Critter::Body::*)(float,float,float) ) &Critter::Body::setGlobalPosition )

I am stumped about this ;(

Was it helpful?

Solution

As DeadMG pointed out, you are missing an ampersand before the member function. The tutorial you linked is also missing it. Some compilers might not care, but g++ does and probably some others do too.

OTHER TIPS

This question seems quite old now, but I figured since you still don't have the answer to your latest edits:

(( void(Critter::Body::*)(Vector3) ) &Critter::Body::setGlobalPosition)

is missing the const qualifier and reference-ampersand in the function-type to cast to. It's got to be:

(( void(Critter::Body::*)(const Vector3&) ) &Critter::Body::setGlobalPosition)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top