문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top