2

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 ;(

Patryk
  • 22,602
  • 44
  • 128
  • 244
  • 1
    Yes, please do attach the errors. I think you just forgot the `&`. – Puppy Apr 24 '11 at 16:36
  • Just in case somebody did not see it : I have attached errors and an another way to do this - I think a proper one, but still I get some errors. – Patryk Apr 24 '11 at 17:32

2 Answers2

1

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)
ltjax
  • 15,837
  • 3
  • 39
  • 62
  • I have almost forgotten about this question to be honest :) I will try to use your code later on and I will post some results ;) – Patryk Feb 06 '12 at 17:37
0

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.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436