Plugins
TypeScriptToLua supports plugins - an interface that allows to customize transpilation behavior.
To add a plugin you have to add it under tstl.luaPlugins
option in the configuration file.
Example:
#
APIvisitors
#
Internally, to process Abstract Syntax Tree of a TypeScript program, TypeScriptToLua implements the visitor pattern. Visitor is a function, called with a processed node and transformation context, and returning a Lua AST node. Plugins can inject their own visitors using visitors
property, overriding standard transformation behavior.
Example:
Example 2:
printer
#
printer
is a function that overrides the standard implementation of the Lua AST printer. It receives some information about the file and the transformed Lua AST. See the LuaPrinter page for more information.
Example:
beforeTransform
#
The beforeTransform
function on plugins is called after gathering the TypeScript program and compiler options, but before any transformation to Lua is done.
It can be used to set up the plugin
afterPrint
#
The afterPrint
function is called after tstl has translated the input program to Lua, but before resolving dependencies and before bundling if configured. You can use this to modify the list of output files and do direct string modifications to them.
beforeEmit
#
The beforeEmit
function is called after the input program has been translated to Lua, after external dependencies have been resolved and included, and after bundling (if configured).