Take the 2-minute tour ×

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

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{
    : Game()

virtual int Loop(void){

static int default_Loop(Game* ptr){
    return ptr->Game::Loop();

static void Lua(lua_State *lua){
    luabind::class_<Game, GameWrapper>("Game")
        .def("Loop", &Game::Loop, &GameWrapper::default_Loop)

Any ideas what I might be doing wrong?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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()
share|improve this answer
Ouch, as much stupid mistake. –  Adam Tomeček Nov 19 '12 at 10:37
add comment

Your Answer


