Problem calling lua functions

Henrique <[email protected]> Sun, 11 May 2014 22:39:31 -0300
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <CA+13w-HUk_xK=CQpJMU6UQ-1hWJnA_t4gOXXSoF9h-sNJUvwtw@mail.gmail.com>
--===============2813375328071856941==
Content-Type: multipart/alternative; boundary=e89a8f647c49d7009b04f92a0486

--e89a8f647c49d7009b04f92a0486
Content-Type: text/plain; charset=UTF-8

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.

--e89a8f647c49d7009b04f92a0486
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div>Hello there, I&#39;ve been trying to c=
reate a callback for a button using luabind, but when a click the buttons I=
 get a segfault.<br><br></div>Here is the function i use to register the C+=
+ functions to lua:<br>


<br>void Callback::registerCallbacks( lua_State *L ) {<br>=C2=A0=C2=A0=C2=
=A0 using namespace luabind;<br>=C2=A0=C2=A0=C2=A0 module( L ) [<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 namespace_(&qu=
ot;Callback&quot;)[<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 def( &quot;game_quit&quot;, &amp;Ca=
llback::game_quit ),<br>


=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 def( &quot;game_start&quot;, &amp;Callback::game_start ),<b=
r>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 def( &quot;game_load&quot;, &amp;Callback::game_load ),<=
br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 def( &quot;start_battle&quot;, &amp;Callback::start_batt=
le )<br>


=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ]<br>=C2=
=A0=C2=A0=C2=A0 ];<br>}<br><br></div>This is how i retrieve the function fr=
om lua:<br><br>typedef LuaFunction luabind::object;<br>cbk =3D new LuaFunct=
ion( button.getLuaType );<br><br>button is of class LuaTable, a wrapper I&#=
39;ve made for luabind::object.<br>


cbk is a pointer to a luabind::object.<br><br></div>if I use (*cbk)(); righ=
t after, the function runs fine.<br><br></div><div>But then, I send cbk to =
a Button constructor which does:<br></div><div>callback =3D cbk;<br></div>

<div>
<br></div><div>And when callback is called inside the button:<br><br>void B=
utton::activate(){<br>=C2=A0=C2=A0=C2=A0 activated =3D 8;<br>=C2=A0=C2=A0=
=C2=A0 (*callback)();<br>}<br><br></div><div>I get a segmentation fault.<br=
><br></div><div>Thanks.<br></div>

</div>

--e89a8f647c49d7009b04f92a0486--


--===============2813375328071856941==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
--===============2813375328071856941==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user

--===============2813375328071856941==--