I have a class that I want to bind to lua. The reduced code might be:
class CSprite2D{
void setPosition(glm::ivec2 val) { m_position = val; }
void setPosition(int posX, int posY) { m_position.x = posX; m_position.y = posY; }
static v开发者_如何学Pythonoid exposeAPI(lua_State* L,const unsigned char* data)
{
assert(L);
luabind::module(L)[
luabind::class_<CSprite2D>("CSprite2D")
.def("setPosition",(void(*)(int,int))&CSprite2D::setPosition)
];
}
When I try to compile, the compiler throws and error:
Error 1 error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(int,int)' c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 2 error C2780: 'luabind::class_<T> &luabind::class_<T>::def(luabind::detail::operator_<Derived>)' : expects 1 arguments - 2 provided c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 3 error C2784: 'luabind::class_<T> &luabind::class_<T>::def(luabind::detail::operator_<Derived>,const Policies &)' : could not deduce template argument for 'luabind::detail::operator_<Derived>' from 'const char [12]' c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 4 error C2784: 'luabind::class_<T> &luabind::class_<T>::def(luabind::constructor<A0,A1,A2,A3,A4,A5,A6,A7,A8,A9>,const Policies &)' : could not deduce template argument for 'luabind::constructor<A0,A1,A2,A3,A4,A5,A6,A7,A8,A9>' from 'const char [12]' c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 5 error C2780: 'luabind::class_<T> &luabind::class_<T>::def(luabind::constructor<A0,A1,A2,A3,A4,A5,A6,A7,A8,A9>)' : expects 1 arguments - 2 provided c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 6 error C2780: 'luabind::class_<T> &luabind::class_<T>::def(const char *,F,Default,const Policies &)' : expects 4 arguments - 2 provided c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
Error 7 error C2780: 'luabind::class_<T> &luabind::class_<T>::def(const char *,F,DefaultOrPolicies)' : expects 3 arguments - 2 provided c:\directo\gameprojects2008\zeleste2d\src\graphics\gpx\sprite2d.cpp 74
I know that cause of the problem is that luabind couldn't deduce the best overload function, but reading the luabind documentation I'm defining the function correctly in luabind.
Any ideas?
Thanks in advance
You are casting the function to the wrong type, you need to cast to a pointer-to-member-function.
Try:
.def("setPosition", (void (CSprite2D::*)(int, int))&CSprite2D::setPosition)
精彩评论