[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Register Lua callback functions from within Lua to C++
- From: Michael Bauroth <Michael.Bauroth@...>
- Date: Mon, 10 Nov 2008 08:31:13 +0100
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