Function 模拟';参数。被调用方';在卢阿
有没有一种方法可以引用Lua中当前正在执行的匿名函数?就像我们可以在JavaScript中使用Function 模拟';参数。被调用方';在卢阿,function,lua,self-reference,Function,Lua,Self Reference,有没有一种方法可以引用Lua中当前正在执行的匿名函数?就像我们可以在JavaScript中使用参数.callee一样 例如: 局部函数newLiftAnimator(obj) 本地计数=0 返回函数(事件) --在每个“enterFrame”事件上设置obj属性的动画 对象y=对象y-1 计数=计数+1 --完成后,删除事件侦听器 如果计数>=100,则 运行时:removeEventListener(“enterFrame”,*****) 结束 结束 结束 运行时:addEventListen
参数.callee
一样
例如:
局部函数newLiftAnimator(obj)
本地计数=0
返回函数(事件)
--在每个“enterFrame”事件上设置obj属性的动画
对象y=对象y-1
计数=计数+1
--完成后,删除事件侦听器
如果计数>=100,则
运行时:removeEventListener(“enterFrame”,*****)
结束
结束
结束
运行时:addEventListener(“enterFrame”,newLiftAnimator(ball))
试试看
没关系。在阅读了Lua的邮件列表后,我想出了一个显而易见的解决方案:
local function newLiftAnimator(obj)
...
local function animator()
...
Runtime:removeEventListener("enterFrame", animator)
end
return animator
end
另一种可能性是使用:
debug.getinfo(1,'f').func
local function newLiftAnimator(obj)
...
local function animator()
...
Runtime:removeEventListener("enterFrame", animator)
end
return animator
end
debug.getinfo(1,'f').func