[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Register Lua callback functions from within Lua to C++
- From: Michael Bauroth <Michael.Bauroth@...>
- Date: Mon, 10 Nov 2008 16:19:41 +0100
I used the Lunar template for this. I will try to find it out, but for a
newbie this thingie could be a little bit tricky (I guess I have no
Or would it be better to open a new thread, because this one has a
different title and is initiallyl solved?
Jan de Vos schrieb:
You need the correct metatable to be set on you userdata object.
If you are not using any binding framework (such as tolua++ or luabind),
you might be able to take a look at how the Button:new() function is
implemented. Do the same in your code, and it will work :-)
If you have no idea of how the Button:new() function was implemented,
chances are that its programmer used some binding framework or other.
The answer to your question greatly depends on that, so please try to
[mailto:firstname.lastname@example.org] On Behalf Of
Sent: maandag 10 november 2008 15:35
To: Lua list
Subject: Re: Register Lua callback functions from within Lua to C++
Unfortunately this doesn't do the trick :(
Let us reduce the complexity of the problem even more ...
Primary I create an C++ object Button in Lua:
btn = Button:new()
btn.RegisterCallback( callback )
In C++ I store the reference ...
m_CbOnMouseDown = luaL_ref( L, LUA_REGISTRYINDEX );
Later on I want to call a function from C++ in Lua like this:
callback( btn )
where btn should be of type Button again, so that I can call
C++ methods on it. I don't use any binding framework at the moment.
// push function
lua_rawgeti( L, LUA_REGISTRYINDEX, m_CbOnMouseDown );
//lua_pushlightuserdata( L, this );
// call function
if ( lua_pcall( L, 1, LUA_MULTRET, 0 ) != 0 )
pushlightuserdata has the disadvantage to give me only type free data.
Were should I embed the call to pushvalue instead?
Peter Cawley schrieb:
It depends on which Lua/C++ binding framework you're using, but I'd
guess that a copy of the Lua-ized 'this' pointer will be at
1, and so you could use lua_pushvalue(L, 1); to push a copy
of it to the
top of the stack.