|
|
|
|
|
by jmaa
2241 days ago
|
|
I do not really agree with the article's (implied?) statement that multivalues are an ugly part of Lua. It's subtle yes, but like most of Lua, is incredibly consistent. For example, let's compare with Python: In Python, you can return multiple arguments as a tuple; it's not possible to have an optional return value without a lot of painful type matching and unpacking. In Lua you can: local result, errmsg = do_stuff()
if not result then
error("Error in do_stuff:"..errmsg)
end
print(result + 5)
If you don't want the error message, just remove ", errmsg", 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. |
|