View Single Post
02-11-23, 08:23 PM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Lua can have ambiguity errors where the compiler gets confused about what part of a line is supposed to do. Since the next line starts with a set of parenthesis, the compiler wouldn't know if it's a set of parameters for a function call continuing from the previous line or a new expression. Remember, Lua is whitespace agnostic and whitespace is allowed between a function reference and the argument list. Newlines don't explicitly define new statements, that's the semicolon's job.

Most times, the compiler is smart and can determine this on its own, but there are a few edge cases where this can happen. In this case, we want it to be recognized as an expression because it fetches the function we want for the next set of parenthesis to call.



Lua 5.1 Reference Manual §2.5.8
As an exception to the free-format syntax of Lua, you cannot put a line break before the '(' in a function call. This restriction avoids some ambiguities in the language. If you write
Code:
a = f
(g).x(a)
Lua would see that as a single statement, a = f(g).x(a). So, if you want two statements, you must add a semi-colon between them. If you actually want to call f, you must remove the line break before (g).
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-11-23 at 09:01 PM.
  Reply With Quote