What is the purpose of ' ; '?

I know that this symbol is used to end lines in most programming languages like C# and C++ but is there any purpose for this in Lua? Can u start a new line with it like in Unity?

Semicolons are optional in both Lua and Luau. You can also use them to separate ambiguous syntax:

-- Example of ambiguous syntax
local function foo()
   --...
end

foo()
;(function() -- Semicolon is required here to let Luau know that this isn't an attempt to call the result of 'foo'
   -- This creates an anonymous function
end)()

Though, I (and Iā€™m sure many others) very rarely come across this problem.


But if you really want to, you can indeed use them at the end of your statements:

local five = 5;
local six = 6;

print(five + six); -- prints "11"
2 Likes

That is really interesting, thanks for letting me know.