lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

normally Google is my friend, but this time I searched several hours but without luck. What I'm looking for is a way, in which I can register from Lua side a callback to C++ as a pointer like this:

Lua:

function OnMouseDown( btn )
    -- do something
end

function createButton()
    btn = Button:new()
    btn:RegisterCallback( OnMouseDown )
    return btn
end;

Button b1 = createButton()


Button is a C++ class accessible from Lua. The class has a method RegisterCallback(), which should take the Lua function pointer and store it internally for later use. What I've found was something like this (doesn't work til now):

int FButton::RegisterCallback( lua_State *L )
{
    m_CbOnMouseDown = luaL_ref( L, LUA_REGISTRYINDEX );

    return 0;
}

What I'm doing wrong?

Any help is higly appreciated.

Thanx in advance.
Micha