Lua Semicolon Conventions

Semi-colons in Lua are generally only required when writing multiple statements on a line.

So for example:

local a,b=1,2; print(a+b)

Alternatively written as:

local a,b=1,2
print(a+b)

Off the top of my head, I can’t remember any other time in Lua where I had to use a semi-colon.

Edit: looking in the lua 5.2 reference I see one other common place where you’d need to use semi-colons to avoid ambiguity – where you have a simple statement followed by a function call or parens to group a compound statement. here is the manual example located here:

--[[ Function calls and assignments can start with an open parenthesis. This 
possibility leads to an ambiguity in the Lua grammar. Consider the 
following fragment: ]]

a = b + c
(print or io.write)('done')

-- The grammar could see it in two ways:

a = b + c(print or io.write)('done')

a = b + c; (print or io.write)('done')

Leave a Comment

tech