Skip to content

Lua: Syntax Errors and Directives

Codes that start with A2C:L: come from reading your Lua: the lexer, the parser and the directive comments. Syntax errors use the words of the host's own Lua compiler and point at the same place, so a script that loads in AutoPlay Media Studio compiles, and one that doesn't fails here with the message you'd get there.

Numbers What
0001 to 0099 Strings, numbers and other tokens (errors)
0100 to 0199 The grammar (errors)
0200 to 0299 Limits, goto and labels (errors)
0300 to 0399 Directive comments (warnings)

A2C:L:E:0001 unfinished-string

A string doesn't end before the end of its line or of the script.

-- unfinished string near '"Main;'
local name = "Main;

Add the closing quote. A string can't span lines unless the line break is escaped with \, or you use a long string ([[...]]).

A2C:L:E:0002 unfinished-long-string

A long string ([[...]]) or a long comment (--[[...]]) isn't closed. Lua 5.3 adds the line it starts on to the message.

Add the closing ]], with as many = signs as the opening bracket has: [==[ closes with ]==].

A2C:L:E:0003 invalid-escape

An escape sequence in a string isn't valid: a \ followed by a character Lua doesn't know, or a \x, \u{...} or decimal escape that's incomplete. Lua 5.1 accepts more escapes than Lua 5.3: "\q" is just q there.

local path = "C:\Temp\new";   -- Lua 5.3: invalid escape sequence near '"C:\T'

Write a backslash as \\: "C:\\Temp\\new".

A2C:L:E:0004 escape-too-large

The value of an escape sequence is too large: a decimal escape above \255, or a \u{...} above what UTF-8 can hold.

A2C:L:E:0005 malformed-number

A numeral isn't a valid number, such as 3e, 0x or 1..2.

local range = 1..2;          -- malformed number near '1..2'

Write spaces around .. after a number: 1 .. 2. AutoPlay Media Studio 8 and Setup Factory 9.7 don't accept hexadecimal floats such as 0x1p4, so neither does autoplay2c for those targets.

A2C:L:E:0006 invalid-long-delimiter

A [ followed by = signs isn't followed by another [, so it starts no long string.

A2C:L:E:0007 nested-long-string

Lua 5.1 only: a [[ inside a long string or comment. Lua 5.1 refuses it, Lua 5.3 doesn't.

Use a long bracket with = signs for the outer string or comment: --[=[ ... [[ ... ]] ... ]=].

A2C:L:E:0100 expected

Something is missing: a keyword, a symbol or a name. When the missing token closes something opened on an earlier line, the message says which line.

if (x > 1) then
    Dialog.Message("Big", "x is big");
-- 'end' expected (to close 'if' at line 1) near <eof>

A2C:L:E:0101 unexpected-symbol

A symbol appears where no expression can start, often because of a typo or a missing operand.

x = = 2;                     -- unexpected symbol near '='

A2C:L:E:0102 ambiguous-call

Lua 5.1 only: a line starts with ( right after an expression on the line before, so Lua can't tell whether you call that expression or start a new statement.

local f = g
(h or print)("hi");          -- ambiguous syntax (function call x new statement)

End the first statement with ;, as local f = g;.

A2C:L:E:0103 arguments-expected

A method call (a:b) has no arguments. Write the parentheses, even when there are no arguments: a:b().

A2C:L:E:0104 vararg-outside

... is used in a function that doesn't take .... Add ... to the function's parameters, or pass the values as named parameters.

A2C:L:E:0105 syntax-error

Lua's plain "syntax error": a statement that is neither a call nor an assignment, such as a lone name, or an assignment to something that can't be assigned, such as (x) = 1.

A2C:L:E:0106 no-loop-to-break

break outside a loop.

A2C:L:E:0200 too-many

A function passes a limit of the Lua compiler: more than 200 local variables, more upvalues than the version allows (60 in Lua 5.1, 255 in Lua 5.3), more than 200 variables on the left of one assignment, or calls nested too deeply. Split the function, or keep values in a table.

A2C:L:E:0201 too-many-levels

Lua 5.1 only: the script nests too deeply, such as hundreds of parentheses or blocks inside each other.

A2C:L:E:0202 label-defined

Lua 5.3 only: a label (::name::) appears twice in the same block.

A2C:L:E:0203 goto-into-scope

Lua 5.3 only: a goto jumps forward past a local declaration into code where that local is visible. Put the local in a do ... end block that ends before the label.

A2C:L:E:0204 no-label

Lua 5.3 only: a goto names a label that isn't visible from it.

A2C:L:W:0300 unknown-directive

A comment starts with --# followed by a name autoplay2c doesn't know as a directive, often a typo. It does nothing.

--#cahce                     -- warning A2C:L:W:0300: unknown directive `--#cahce`

A comment that starts with --## or --# and a symbol is an ordinary comment, so banners like --##### stay silent.

A2C:L:W:0301 malformed-directive

A directive's name is followed by something other than white space, such as --#cache!, or its arguments aren't UTF-8 text. The directive does nothing.

A2C:L:W:0302 unattached-directive

A directive isn't followed by a statement, because it's at the end of a block or a script. It has no effect. Put it on the line before the statement it is for.