lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
For me, there are two way of doing it.

If setCallback is a C function, you can try this

int callback_reference;

setCallback( lua_State *L)
{
    //anima is at -1 on stack
    reference = luaL_ref ( L, LUA_REGISTRYINDEX);
}

callback( lua_State *L )
{
    |lua_rawgeti(L, |REGISTRYINDEX|, |reference |);
  lua_push( L, runner ); //depends of your system
  lua_pcall( L, 1, 0, 0 );
|}

don't forget to release the ref with luaL_unref()

If your object is a lua object try this

{
    lua_getglobal( L, "runner" );
    lua_getfield( L, -1,"callback" ); //stack : runner, function
    lua_insert( L, -2 ) ; // stack: function, runner
    lua_pcall( L, 1, 0, 0 );

}

Now it depends how you have implemented C binding in lua. With this
information, I can give you the right method to do it

Julien


Jose Marin wrote:
>> In lua, a function is a variable.
>
> You are right, Julien, but the 'anima' function will
> be called in C++ code;
>
> The 'setCallback' is a method of the Animation class.
>
> My doubt is how to declare the method 'setCallback' in
> tolua, and how to store in the C++ code the reference
> to the Lua funcion and how to call it later, passing
> the 'runner' object.
>
>
>
>
>> when you write
>>
>> function anima(self)
>> - -- Do something with self...
>>
>> end
>>
>> you actually writing
>>
>> anima = function( self )
>>
>> - -- Do something with self...
>>
>> end
>>
>> so in your callback, just do
>>
>> runner:setCallback(anima)
>>
>>      self.somefield = anima;
>> end
>>
>> runner:Callback()
>>    self.somefield( self );
>> end
>>
>> Julien
>>
>>
>
>
>        
> _______________________________________________________
> Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu
celular. Registre seu aparelho agora!
> http://br.mobile.yahoo.com/mailalertas/
> 
>
>
>


- --
- --
Julien Hamaide
Engineering Coach
10Tacle Studios Belgium / Elsewhere Entertainment
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFE3J4D/nbvGx8yYLARAr+fAJ4o7356CvVjcwnFDeIRiNADM4r+9gCfenaR
aUUFQFL+YO0bfNWLeZjgybs=
=3RJz
-----END PGP SIGNATURE-----