-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of
Michael Bauroth
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
additonal
C++ methods on it. I don't use any binding framework at the moment.
// push function
lua_rawgeti( L, LUA_REGISTRYINDEX, m_CbOnMouseDown );
//push parameter(s)
//lua_pushlightuserdata( L, this );
//lua_pushvalue(L, 1);
// call function
if ( lua_pcall( L, 1, LUA_MULTRET, 0 ) != 0 )
{
// error
}
pushlightuserdata has the disadvantage to give me only type free data.
Were should I embed the call to pushvalue instead?
Best Regards
Micha
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
stack index
1, and so you could use lua_pushvalue(L, 1); to push a copy
of it to the
top of the stack.