[luabind] Problem calling lua functions
Brought to you by:
arvidn,
daniel_wallin
From: Henrique <hen...@gm...> - 2014-05-12 01:39:38
|
Hello there, I've been trying to create a callback for a button using luabind, but when a click the buttons I get a segfault. Here is the function i use to register the C++ functions to lua: void Callback::registerCallbacks( lua_State *L ) { using namespace luabind; module( L ) [ namespace_("Callback")[ def( "game_quit", &Callback::game_quit ), def( "game_start", &Callback::game_start ), def( "game_load", &Callback::game_load ), def( "start_battle", &Callback::start_battle ) ] ]; } This is how i retrieve the function from lua: typedef LuaFunction luabind::object; cbk = new LuaFunction( button.getLuaType ); button is of class LuaTable, a wrapper I've made for luabind::object. cbk is a pointer to a luabind::object. if I use (*cbk)(); right after, the function runs fine. But then, I send cbk to a Button constructor which does: callback = cbk; And when callback is called inside the button: void Button::activate(){ activated = 8; (*callback)(); } I get a segmentation fault. Thanks. |