lua-users home
lua-l archive

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


>>And third, how do to pass "functors" to a function in lua?, maybe for...
i have a lua gui loop, and the callbacks must be executed in c++.. so..
i want to call the lua function set_callback() with a C++ "functor" as
argument. (and four :), can i set these functors callbacks in tag methods?)

I'm not using functors, just using Lua directly... The way I am doing this
is to have a Lua reference in my widget class. When you do the
set_callback() method from Lua to C++ you reference lock the Lua function
and remember the reference (ie. lua_ref(ls,1);). Then when you want to call
the method back you just do your Lua function call having got your Lua
callback through the reference (ie. lua_getref) push your arguments on and
lua_call. Pretty straight forward.

I assume you are doing this to respond to events from the GUI. You could
deal with these on the C++ side or the Lua side. ie. a switch on event type
on C++ followed by typed call to Lua, or you could pass the event info to
Lua and let Lua code handle the callback.