lua-users home
lua-l archive

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


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.