lua-users home
lua-l archive

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

On 20/12/15 10:48 AM, Dirk Laurie wrote:
2015-12-20 14:31 GMT+02:00 Soni L. <>:

On 20/12/15 05:41 AM, Dirk Laurie wrote:
2015-12-20 6:19 GMT+02:00 Egor Skriptunoff <>:
On Fri, Dec 18, 2015 at 3:19 PM, Rena <> wrote:
The exception is when it's ambiguous:
x = f
(a or b):c()
That expression could be interpreted as two statements or one (remove
line break and see). In that case Lua is kind enough to make an
exception to
the "ignore whitespace" rule and raise an error
I've always thought that Lua treats this chunk as absolutely correct way
write the following code:
x = (f(a or b)):c()
It depends on the Lua version. It changed between Lua 5.1 and Lua 5.2,
A linebreak between a function and its arguments used to be illegal,
and an error message was issued. As from 5.2, no matter what whitespace
sits between the two parts (several blank lines if you like), x = (f(a
or b)):c()
is performed.

It changed bewteen Lua 5.0 and Lua 5.2.

In Lua 5.0, a linebreak between a function and its arguments made 2
statements, not a function and its arguments. (so a newline worked like a
Did you try that out? On my system it does as I said.

Lua 5.0.3  Copyright (C) 1994-2006 Tecgraf, PUC-Rio
a = {c=print}
b = {c=print}
a:c(); b:c()
table: 0x1003d40
table: 0x1004150
f = function(t) if t==a then return b else return t end end
f(a or b):c()
table: 0x1004150
x = f
(a or b):c()
stdin:3: ambiguous syntax (function call x new statement) near `('

Hmm... Older versions of Lua then? I looked at this a while ago but I don't remember much of it anymore...

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.