TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Everything You Didn't Want to Know About Lua's Multi-Values

19 点作者 benaiah大约 5 年前

1 comment

jmaa大约 5 年前
I do not really agree with the article&#x27;s (implied?) statement that multivalues are an ugly part of Lua. It&#x27;s subtle yes, but like most of Lua, is incredibly consistent.<p>For example, let&#x27;s compare with Python: In Python, you can return multiple arguments as a tuple; it&#x27;s not possible to have an optional return value without a lot of painful type matching and unpacking. In Lua you can:<p><pre><code> local result, errmsg = do_stuff() if not result then error(&quot;Error in do_stuff:&quot;..errmsg) end print(result + 5) </code></pre> If you don&#x27;t want the error message, just remove &quot;, errmsg&quot;, and it will work as expected. This is incredibly flexible, which is exactly what I want in my dynamic languages. In Python, you would get an type error when attempting to add together a tuple and an integer.
评论 #23083331 未加载
评论 #23083075 未加载
评论 #23082337 未加载