TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

19 pointsby benaiahabout 5 years ago

1 comment

jmaaabout 5 years ago
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 未加载