【发布时间】:2014-12-07 12:59:29
【问题描述】:
有没有办法停止一个函数而不使它成为nil?像“function.stop”之类的东西?
【问题讨论】:
-
你的“停止”是什么意思?随时返回函数?
-
请改进您的问题
有没有办法停止一个函数而不使它成为nil?像“function.stop”之类的东西?
【问题讨论】:
您可以在函数结束前退出函数,只需调用“return”s 语句:
local function doSomething()
if leaveEarly then
return
else
-- do other stuff
end
-- do more stuff
end
【讨论】:
根据documentation使用do return end
function foo ()
do return end
... -- statements not reached
end
【讨论】:
除非你调用它,否则函数不会做任何事情。如果您正在谈论事件侦听器,例如
Runtime:addEventListener( "enterFrame", win)
--win is the name of the function, which is called once every frame
然后您可以像这样删除该事件侦听器:
Runtime:removeEventListener( "enterFrame", win)
--now win is no longer called every frame
如果这不是你的意思,你能发布一些你的代码吗?
【讨论】: