Skip to content

Emit Mode

tslua has two emit modes, controlled by the emitMode option in tsconfig.json or the --emitMode CLI flag.

{
"tstl": {
"emitMode": "optimized"
}
}

Matches TSTL’s Lua output as closely as possible. Use this when you need byte-for-byte compatibility with TSTL, or when comparing output between the two transpilers.

Emits cleaner Lua where tslua can prove the result is semantically equivalent. Every optimization preserves identical runtime behavior; the Lua evaluates to the same result as the default mode.

This mode is a work in progress. Current optimizations:

AreaDefault (tstl)OptimizedNotes
tostring() in concatWraps all non-string operands including numeric varsSkips wrapping for numeric typesLua .. handles numbers natively
C-style for loopswhile loop with manual init/incrementfor i = start, limit when pattern matchesSimpler, faster Lua
Map/Set for-ofAllocates intermediate tablesZero-garbage stateless iteration via custom lualib helpers ↗Less GC pressure

More optimizations will be added over time. If you find a case where optimized mode changes runtime behavior, please open an issue ↗.