如何退出Lua脚本的执行
发布时间:2020-12-15 00:21:25 所属栏目:大数据 来源:网络整理
导读:我想在某种情况下退出执行Lua脚本。 示例: content = get_content()if not content then -- ( Here i want some kind of exit function )next_content = get_content()--example there can lot of further checks 这里我想要,如果我没有得到内容,我的脚本
我想在某种情况下退出执行Lua脚本。
示例: content = get_content() if not content then -- ( Here i want some kind of exit function ) next_content = get_content() --example there can lot of further checks 这里我想要,如果我没有得到内容,我的脚本假设终止是不应该去检查下一个。 解决方法
从
lua api doc提取:
出于句法原因,中断或返回可以仅作为块的最后一个语句(换句话说,作为块中的最后一个语句,或者在结束之前,另一个或者直到最后一个)都可以出现。例如,在下一个例子中,break是当前块的最后一个语句。 local i = 1 while a[i] do if a[i] == v then break end i = i + 1 end 通常,这些是我们使用这些语句的地方,因为跟随它们的任何其他语句是无法访问的。然而,有时候,在块的中间写一个返回(或中断)可能是有用的;例如,如果您正在调试函数并希望避免其执行。在这种情况下,您可以在语句周围使用显式的do块: function foo () return --<< SYNTAX ERROR -- `return' is the last statement in the next block do return end -- OK ... -- statements not reached end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |