Skip to content

Directives

autoplay2c compiles your code so that it behaves exactly like the interpreter, in every case, even the odd ones. Sometimes, though, you know more than the compiler does. You might know that Input.SetText will always be the same function, or that a small helper never changes. A directive tells the compiler so, and lets it produce faster code in return, or spare you a warning that doesn't apply to your code.

A directive is a comment that starts with --#, on the line before a statement:

--#cache
function UpdateForm(data)
    Input.SetText("Name", data.name);
    Label.SetText("Status", "Saved");
end

To the interpreter a directive is just a comment, so the same script still runs unchanged in AutoPlay Media Studio's preview, without autoplay2c.

Available Directives

Directive What it does
--#cache Looks up globals such as Input.SetText once, and remembers them
--#inline Copies a small function's body into the places that call it
--#noyield Says that code never yields, and silences the coroutine warnings for it

The Rules

  • A directive applies to the statement that follows it. Several directives can come before the same statement, each on its own line.
  • A directive starts with --#, followed directly by its name. --## and -- # are ordinary comments, so banners like --##### are fine.
  • Directives don't take arguments. Words after the name give a warning and are ignored.
  • An unknown directive, such as a typo like --#cahce, gives a warning and does nothing.
  • A directive without a statement after it gives a warning and does nothing.

Each directive makes a promise

A directive is a promise you make about your code. Each directive's page tells you exactly what that promise is, and what happens when your code breaks it. Directives never change anything else about your program. When in doubt, leave them out, since everything works without them.

Directives are optional. autoplay2c already applies many optimizations by itself, on every build, without changing anything about how your code behaves.