Considerations

Because of the expressive parentheses-less way of calling functions, some restrictions must be put in place to avoid parsing ambiguity involving whitespace.

The minus sign plays two roles, a unary negation operator and a binary subtraction operator. Consider how the following examples compile:

MoonScript:

a = x - 10
b = x-10
c = x -y
d = x- z

Lua:

local a = x - 10
local b = x - 10
local c = x(-y)
local d = x - z

The precedence of the first argument of a function call can be controlled using whitespace if the argument is a literal string. In Lua, it is common to leave off parentheses when calling a function with a single string or table literal.

When there is no space between a variable and a string literal, the function call takes precedence over any following expressions. No other arguments can be passed to the function when it is called this way.

Where there is a space following a variable and a string literal, the function call acts as show above. The string literal belongs to any following expressions (if they exist), which serves as the argument list.

x = func"hello" + 100
y = func "hello" + 100

Lua:

local x = func("hello") + 100
local y = func("hello" + 100)

results matching ""

    No results matching ""