[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Register Lua callback functions from within Lua to C++
- From: Michael Bauroth <Michael.Bauroth@...>
- Date: Mon, 10 Nov 2008 08:31:13 +0100
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:
function OnMouseDown( btn )
-- do something
btn = Button:new()
btn:RegisterCallback( OnMouseDown )
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 );
What I'm doing wrong?
Any help is higly appreciated.
Thanx in advance.