Reputation: 209
I just got myself into weird problem with Luabind. I want to inherit C++ classes from Lua, but the way described in Luabind documentation just doesn't work.
function MyGame.__init()
Game.__init(self)
end
This piece of code just crashes the application, because self
seems undefined (returns nil
if printed out).
I'm using wrapper struct as described in documentation.
struct GameWrapper: Game, luabind::wrap_base{
GameWrapper()
: Game()
{}
virtual int Loop(void){
call<int>("Loop");
}
static int default_Loop(Game* ptr){
return ptr->Game::Loop();
}
static void Lua(lua_State *lua){
luabind::module(lua)
[
luabind::class_<Game, GameWrapper>("Game")
.def(luabind::constructor<>())
.def("Loop", &Game::Loop, &GameWrapper::default_Loop)
];
}
};
Any ideas what I might be doing wrong?
Upvotes: 0
Views: 388
Reputation: 473437
but way described in Luabind doc just doesn't work.
Yes it does. You just didn't do it right. Specifically, you didn't notice the use of the :
instead of the .
. Which has a well-defined meaning in Lua when declaring a function:
function MyGame:__init()
Game.__init(self)
end
Upvotes: 1