Skip to content

Diagnostics

autoplay2c reports errors and warnings with the place they're about: the file, the script in a project, the line and the column. This way, you can always find the code a message is about. Each message also has a code, which says what kind of message it is and links to its explanation here.

tools.lua:12:5: error A2C:L:E:0100: '=' expected near 'x'
MyProject.autoplay[page/Main/OK/On Click]:2:5: error A2C:L:E:0101: unexpected symbol near '<eof>'
MyProject.autoplay[dialog/Ask/OK/On Click]:1:1: warning A2C:L:W:0300: unknown directive `--#cahce`

In a project, the part between brackets names the script:

Script Written as
Global functions globals
A project event project/On Startup
A page event page/Main/On Show
An object event on a page page/Main/OK/On Click
A dialog or an object on a dialog dialog/Ask/On Show, dialog/Ask/OK/On Click
Code that creates serialized objects page/Main/(objects)

Lines and columns count from 1, within the script.

Codes

A code is written as A2C:<part>:<kind>:<number>, such as A2C:L:E:0101. Every code also has a name, such as unexpected-symbol, which the JSON messages carry too. A code never changes its meaning, and a code that goes out of use is never given to another message.

The part says which part of autoplay2c the message comes from, and each part has a page:

Part Page About
L Lua Reading your Lua: syntax errors and directive comments
IR IR Compiling it: what can't be compiled, directives, coroutines and the optimizations
N Native The machine code
C C The C backend and tcc
PE PE Writing the DLL
P Project AutoPlay projects and project files
B Build Options, targets and files

The kind says what the message is:

Kind Meaning
E An error: the build stops
W A warning: the build goes on, but part of your code may not do what you expect
O An optimization the compiler applied
M A missed optimization: one the compiler considered and didn't apply, and why

The number has four digits. Within a part, numbers are grouped by subject, as each part's page shows.

Optimizations and missed optimizations are reported in the compilation log, when you ask for it.

Errors

An error stops the build, and nothing is written. Syntax errors use the same words, and point at the same place, as the host's own Lua would. A project with errors in several scripts reports all of them at once.

Other errors are about the build itself, such as a file that can't be read, a missing target, an invalid module name or a character that Windows-1252 doesn't have. These have no place:

error A2C:B:E:0001: a Lua file needs a target: --target ams8|ams9|suf9-x86|suf9-x64|suf10-x86|suf10-x64

Warnings

A warning doesn't stop the build, but you should read it, because it means part of your code may not do what you expect.

Code Warning What it means
A2C:L:W:0300 unknown directive `--#cahce` A directive with a name autoplay2c doesn't know, often a typo. It does nothing.
A2C:L:W:0302 directive `--#cache` is not followed by a statement; it has no effect A directive at the end of a block or script.
A2C:IR:W:0100 `--#cache` takes no arguments; they are ignored Words after a directive's name.
A2C:IR:W:0101 `--#inline` applies to function definitions; it has no effect here --#inline on something that isn't a function.
A2C:IR:W:0103 `Twice` is assigned again on line 4: its inlined calls keep running the body defined here The name of an --#inline function is assigned another value, which breaks the directive's promise.
A2C:IR:W:0104 `Log` is assigned again, but `--#cache` caches it (on line 4) A name --#cache caches is assigned in two places or in a loop, which breaks the directive's promise.
A2C:IR:W:3002 to 3007 `f` is not inlined: it takes `...` The compiler declined to inline a function, and says why. See --#inline.
A2C:IR:W:0110 coroutine.yield can't yield from compiled code See Coroutines. The yield raises an error when it runs. --#noyield silences it where you know it never runs in a coroutine.
A2C:IR:W:0111 the function given to coroutine.create is compiled, so neither it nor what it calls can yield The same, for coroutine.create and coroutine.wrap. In Lua 5.1 the call itself fails, since it only takes Lua functions.
A2C:P:W:0100 the project publishes its data folder as `AutoPlay`, but paths in its scripts are made to name `data` The data folder your scripts name differs from the one the project is published with.

The Compilation Log

Every build keeps a log of what the compiler did with each function of your code: how much of it became native code, which optimizations it applied and where, and which it missed. By default a build only reports errors and warnings. Ask for more with --diagnostics (or Diagnostics in the project file):

Level Reports
warnings Errors and warnings only. This is the default.
missed Also each function's native share, the missed optimizations, and a summary
applied Also every optimization applied
all Also the optimizations that are always on, everywhere they apply
a2c build tools.lua --target ams8 --diagnostics applied
tools.lua: function main: 80% native (4 of 5 operations), 7 optimizations, 0 missed
tools.lua: optimization A2C:IR:O:6001 placed-locals
tools.lua: optimization A2C:N:O:1003 number-registers-x86: 1 variable
tools.lua: optimization A2C:N:O:2001 rotated-loop: 1 loop
tools.lua:5:1: optimization A2C:IR:O:1001 numeric-local: `total`
tools.lua: line 6: optimization A2C:IR:O:4001 native-for
tools.lua:6:1: optimization A2C:IR:O:1001 numeric-local: `i`
tools.lua:7:13: optimization A2C:IR:O:1050 number-expression
tools.lua:1: function lerp: 100% native (3 of 3 operations), 5 optimizations, 0 missed
tools.lua: line 1: optimization A2C:IR:O:1020 number-parameter: `a`
tools.lua: line 1: optimization A2C:IR:O:1020 number-parameter: `b`
tools.lua: line 1: optimization A2C:IR:O:1020 number-parameter: `t`
tools.lua: line 1: optimization A2C:IR:O:1060 native-entry
tools.lua:2:12: optimization A2C:IR:O:1050 number-expression
summary: 2 functions, 87% native (7 of 8 operations), 12 optimizations applied, 0 missed

Each function comes with its line, in the order of your source, followed by its optimizations. In a project, each script is a function of its own, named after the script:

MyProject.autoplay[page/Main/On Key]: script: 33% native (1 of 3 operations), 2 optimizations, 0 missed

A function's native share counts its operations: arithmetic, comparisons, reading and storing fields and elements, calls and loops. An operation counts as native when it's computed without calling into the host's Lua, or natively after one check of its values (a dynamic local, a library function that turns out to be the host's). The rest go through the host's Lua, as the interpreter would run them. A low share is where a change to your code pays most: the functions with the lowest share are the ones to look at first, and their missed optimizations say what stands in the way.

The function main is the code of a Lua file outside its functions; in a project, it's the code that holds the scripts together, which does nothing worth counting.

Missed optimizations say what stood in the way, and where:

tools.lua:6:1: missed A2C:IR:M:1003 numeric-local-mixed: `sum` is given `sum + t[i]` on line 9
tools.lua:7:1: missed A2C:IR:M:2003 native-array-escapes: `seen` is passed to a function on line 14
tools.lua:12:1: missed A2C:IR:M:3021 direct-call-assigned: `step` is assigned on line 30

A missed optimization is only reported where your code looks like it meant to have it: a local given a number somewhere, or used in arithmetic; a table indexed by numbers; a table of named fields read by name. A local that only ever holds strings isn't reported as a missed number.

Silencing

You can ask autoplay2c not to report a warning, or a missed or applied optimization, by its code or its name: --allow on the command line, or Allow in the project file. Errors can't be silenced.

a2c build tools.lua --target ams8 --allow yield-from-compiled
a2c build tools.lua --target ams8 --diagnostics missed --allow A2C:IR:M:1003,native-array-escapes
"Allow": ["yield-from-compiled", "A2C:IR:M:1003"]

A silenced diagnostic isn't reported at any level, and the compilation log doesn't count it: a function's missed optimizations and the summary leave it out. A name or code autoplay2c doesn't know stops the build with an error, so a typo never goes unnoticed.

Errors at Run Time

Errors that your compiled code raises while it runs are the interpreter's errors, with the same message. They have no code. Their position names the module's Lua source and its line:

core.lua:123: attempt to index global 'Config' (a nil value)

For a plain module that's your own Lua file. For a project, it's the module source autoplay2c made from all your scripts. Keep it with the Module source option on the Compiler page (or --emit lua) to find the line: it's written as core.intermediate.lua. Each script keeps its own lines in that file, one after the other.

Note

Some errors raised by functions you call lose their position or the function's name. Read more in Limitations.