lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I believe that theoretically it might change the behavior of existing code, since if you have the following:
function foo()
Let's say that `do_something` returns a boolean indicating success or failure, and that result is asserted on.  But assert returns its argument, so now that assert line is returning a value, which would then be returned from the function since it is the last _expression_ in the function, kind of like `1`.  So previously the function returns nothing, and now with your feature it returns true (when it returns).

On Sun, Jun 20, 2021 at 3:30 PM Andrew Yan <> wrote:
In Lua 5.3, this code is unparseable:
function huh() 1 end
Would it be possible in future versions of Lua to instead make it return `1` when called, i.e. to permit a final optional _expression_? AFAIK this wouldn't break anything since the above statement can't be parsed anyways.

Proposed example:
function huh() 1 end
print(huh()) -- prints 1

The motivation for this is lua configuration files.
-- statements...
The desired process is that the above block would be `load`ed and operated on.
As of current the above code block does not parse, and it would be nice if it did.

Previous discussion I found: