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.

Intermediate Files

autoplay2c can keep what it made of your code: the module's Lua source (all your scripts in one file), the generated C, the IR listing and the native code listing. Choose them on the Compiler page or with --emit. They're useful for looking up the line a run-time error names, or for seeing what the compiler did.

Intermediate files hold your code

Each of them shows your program's code as plainly as the scripts themselves. Never publish them, and never give them away with the program.

To keep them out of what you publish, autoplay2c writes them to a folder of their own, a2c-intermediate, next to your project and outside CD_Root. They're named <module>.intermediate.<extension>, such as core.intermediate.lua. Every build that writes one warns about it (A2C:B:W:0100), and once you turn one off, the next build removes it, along with the folder once it's empty. That build also removes the intermediate files that version 2.0.0-beta wrote next to the DLL, in CD_Root\AutoPlay\Scripts.

The Startup Check

In case intermediate files are published anyway, say because they were copied into CD_Root or because a web or email executable picked them up, the rewritten project checks for them each time the program starts. Right after loading the module, the Globals script looks through the program's folder (_SourceFolder) and every folder in it for files named *.intermediate.lua, .c, .ir or .asm. If it finds any, it lists them in a warning dialog. Republish the program without them.

The check is on by default. Turn it off with Warn at startup on the Compiler page, with --no-source-check, or with "SourceCheck": false in the project file. Every build without it warns (A2C:B:W:0101).

Note

The program's users see the dialog too, so it's worth running the published program once before you hand it out. The search looks through the whole folder the program runs from, so it takes a moment longer when that folder holds many files.

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 in a2c-intermediate\core.intermediate.lua. It's never named core.lua, which require "core" would load instead of the DLL.
  • The rewritten project is written last, after the DLL, so a project that calls a module never exists without that module.