Export as Global
By default, tslua wraps each module’s exports in a ____exports table and returns it, matching standard Lua module conventions. The exportAsGlobal option strips this wrapper and emits exported declarations as bare globals instead.
This is useful for embedded Lua environments where scripts run in a global scope rather than as require()-able modules.
Set exportAsGlobal in tsconfig.json:
{ "tstl": { "exportAsGlobal": true }}Or use the CLI flag:
tslua -p tsconfig.json --exportAsGlobalExample
Section titled “Example”Given this TypeScript:
export const SPEED = 200;export const GRAVITY = 9.8;export const PLAYER_NAME = "hero";Default output (module wrapper):
local ____exports = {}____exports.SPEED = 200____exports.GRAVITY = 9.8____exports.PLAYER_NAME = "hero"return ____exportsWith exportAsGlobal: true:
SPEED = 200GRAVITY = 9.8PLAYER_NAME = "hero"Exports become top-level declarations, accessible to the host environment without a module wrapper.
Selective matching
Section titled “Selective matching”Instead of a boolean, exportAsGlobal accepts a regex string to selectively apply to specific files:
{ "tstl": { "exportAsGlobal": "\\.script\\.ts$" }}This applies export-as-global only to files matching the pattern (e.g. game.script.ts), while other files (e.g. util.ts) keep their module wrappers. Useful when some files are entry-point scripts and others are shared modules.