lua-users home
lua-l archive

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


Sorry for the noise.

A solution is to use References (http://www.lua.org/pil/27.3.2.html).

and instead of 'obj1._onUpdate_ = onUpdate'1 I can use' obj1:onUpdate(onUpdate1)' , storing in the C++ class the reference (a simple int) to the function to be called later.

Regards

Jose



De: Jose Marin <jose_marin2@yahoo.com.br>
Para: "lua-l@lists.lua.org" <lua-l@lists.lua.org>
Enviadas: Terça-feira, 13 de Março de 2012 10:48
Assunto: Callbacks for Lunar

Hi,

I´m using Lunar (http://lua-users.org/wiki/CppBindingWithLunar for binding Lua to my application, but I have a problem.

I need that the created objects have callbacks functions to be called in C++ code, like in this example:


function Obj1Update()
...
end

function Obj2Update()
...
end

obj1 = Object:new()
obj2 = Object:new() 

obj1._onUpdate_ = Obj1Update
obj2._onUpdate_ = Obj2Update 

Then, in C++ code, I need to call the "onUpdate" function for the object.

Other callbacks could be "onCollide", "onClick", etc.

Is that possible?

Thanks

Jose