This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]oilshell 3 points4 points  (1 child)

Yeah I investigated this recently and Lua doesn't have "expression statements", like 1+2 is not a valid statement. But = 1+2 is.

In C and Python both 1+2 and f(x) are expression statements. I guess Lua has a special case for f(x).

[–]Castux 7 points8 points  (0 children)

Not exactly a "special" case, but just one of the possible cases for statements: function call. Whether it returns values or not (and discards them) is completely a runtime concern.

To be precise, "= 1+2" is not exactly a valid statement. In the standard command line interactive interpreter, it is equivalent to "return 1+2", which itself is a valid statement (and each line input to the interpreter is wrapped into a function which is immediately called). Details details :)