Question

I have a lua "animation variable" which has a callback function used in an animation loop.

local av = AnimationVariable(ticker.Position.Y)
...
av:addCallback( ** animation function goes here **)

Skipping over details, this addCallback function is defined as follows in C++:

void LuaUIAnimationVariable::addCallback(luabind::object callback);

and when the animation variable is updated, the callback is executed as such (we call the function with one argument):

luabind::call_function<void>(boost::ref(callback), newValue);

My question is the following: How can I use a member function with addCallback? Assuming I have a Ticker:animate(ypos) function, using addCallback on a Ticker instance addCallBack(ticker:animate) does not compile, and addCallBack(ticker.animate) does not work. I understand that member functions in lua have an implicit "self" first parameter.

Any solution or am I forced to use a global function?

Was it helpful?

Solution

Not sure if I understand your question, but if you mean a Lua member function, you can use a closure:

av:addCallback(function(yval) ticker:animate(yval) end)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top