Skip to content

AutoPlay Projects

When you give autoplay2c an AutoPlay Media Studio 8 or 9 project, it does three things:

  1. It compiles every script in the project into one module DLL.
  2. It writes a copy of the project in which each script is replaced by a call into that module.
  3. It leaves your own project alone, so you keep working in the original.
a2c build MyProject.autoplay

By default the module is CD_Root\AutoPlay\Scripts\<module>.dll and the copy is MyProject.a2c.autoplay, both next to your project. The module name is made from the project's file name, so My Project - v2.autoplay gives my_project_v2. You can choose all three yourself in a project file, with the options in Building, or on the Project page of the application.

Open the rewritten project in AutoPlay Media Studio and publish it as usual. It uses the same CD_Root folder, which is where the module DLL now is.

Tip

Rebuild after every change to your project, and only publish the rewritten copy. Changes you make in the rewritten copy are lost on the next build.

Which Scripts

Every script with code in it is compiled:

  • the global functions (the project's Globals script),
  • project events (On Startup, On Shutdown, and so on),
  • page and dialog events (On Show, On Preload, On Key, and so on),
  • the events of every object on every page and dialog.

Empty scripts stay empty.

What the Scripts Become

Each script becomes one function of the module, named f0, f1, f2 and so on, in the order they appear in the project. The script itself is then replaced by a call to that function:

Script Becomes
Globals core = require "core"; followed by core.f0();
A project event core.f1();
A page or dialog event core.f2(this);
An event with arguments, such as On Key core.f3(this, e_Key, e_Modifiers);

Here, core is the module name. The Globals script loads the module and keeps it in the global variable with that name, so every other script can reach it.

Your code keeps working the way it did. this is still the object or page the event belongs to, event arguments such as e_Key keep their names, and the global variables and functions you define in one script are still visible in all the others.

Note

The module's global variable (core in the examples) belongs to autoplay2c. Don't assign to a global with that name in your own scripts.

Errors in Your Scripts

Every script is checked on its own before anything is built, so a syntax error tells you exactly which script it's in:

MyProject.autoplay[page/Main/OK/On Click]:2:5: error A2C:L:E:0101: unexpected symbol near '<eof>'

All scripts with errors are reported in one go, and nothing is written. Read more in Diagnostics.

Text and Characters

Scripts are compiled in Windows-1252, which is the code page AutoPlay Media Studio runs them in. A character that this code page doesn't have, in a string or in a comment, is an error that names the script and the line.

More

Technical details
  • Only Script elements change. Everything else in the project is written back byte for byte as it was read: the encoding, line breaks, character references and the AutoPlay Media Studio 9 plugin settings. A project in which nothing changes comes out identical to the original, which is tested on hundreds of real projects.
  • The module is one table of functions, returned by the module's main chunk. The table itself has no name inside the module, so no script can see or overwrite it by accident.
  • A script that uses ... at its top level gets ... as a parameter.
  • Event arguments come from the event's Args in the project: each comma or semicolon separated part gives its last word, if that can be a Lua name. This also works for plugin events with unusual argument lists.
  • Each script keeps its own lines in the module source, so a run-time error names the line in the module's Lua source (core.lua:123:). Keep that source with the Module source option (or --emit lua) to look it up; it's written as core.intermediate.lua, so that require "core" still loads the DLL.
  • The rewritten project is written last, after the DLL, so a project that calls a module never exists without that module.