Skip to content

CLI Reference

Terminal window
tslua -p tsconfig.json
tslua -p tsconfig.json --outdir dist
tslua -p tsconfig.json --watch
FlagDescriptionDefault
-p, --projectPath to tsconfig.json
--outdirOutput directory for Lua filesstdout
--luaTargetLua target version (JIT, 5.0-5.5, universal)JIT
--emitModetstl (match TSTL output) or optimizedtstl
--luaLibImportHow lualib is included: require, inline, nonerequire
--luaBundleBundle all modules into a single Lua file
--luaBundleEntryEntry point for bundle mode
--exportAsGlobalStrip module wrapper, emit exports as globalsfalse
--noImplicitSelfDefault functions to no-self unless annotatedfalse
--sourceMapGenerate .lua.map source map filesfalse
-w, --watchWatch for file changes and rebuildfalse
--timingPrint phase timings to stderrfalse
--verbosePrint each output file pathfalse
--diagnosticFormatDiagnostic format: tstl or nativetstl
--cpuprofileWrite CPU profile to file

Transpile TypeScript to Lua. Accepts source via -e flag, positional argument, or stdin.

Terminal window
tslua eval -e 'const greet = (name: string) => `Hello, ${name}!`'
greet = function(____, name) return ("Hello, " .. name) .. "!" end

Loops and standard library calls are translated idiomatically:

Terminal window
echo 'for (const x of [1, 2, 3]) { console.log(x) }' | tslua eval
for ____, x in ipairs({1, 2, 3}) do
print(x)
end

Classes produce full Lua object setup:

Terminal window
tslua eval -e 'class Dog { name: string; constructor(n: string) { this.name = n } bark() { return this.name + " barks" } }'
local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
Dog = __TS__Class()
Dog.name = "Dog"
function Dog.prototype.____constructor(self, n)
self.name = n
end
function Dog.prototype.bark(self)
return self.name .. " barks"
end

The --trace flag annotates each statement with the TS AST node that produced it:

Terminal window
tslua eval --trace -e 'const x = 1 + 2'
--[[trace: KindVariableStatement]]
x = 1 + 2
FlagDescription
-e, --exprTypeScript source to transpile
--traceEmit --[[trace: ...]] comments on each statement

Print the TypeScript AST tree. Useful for debugging transforms.

Terminal window
tslua ast -e 'const x = [1, 2, 3]'
SourceFile
VariableStatement
VariableDeclarationList const
VariableDeclaration name="x"
Identifier text="x"
ArrayLiteralExpression
NumericLiteral text="1"
NumericLiteral text="2"
NumericLiteral text="3"
EndOfFile
FlagDescription
-e, --exprTypeScript source to parse

Generate shell autocompletion scripts.

Terminal window
# Bash
tslua completion bash > /etc/bash_completion.d/tslua
# Zsh
tslua completion zsh > "${fpath[1]}/_tslua"
# Fish
tslua completion fish > ~/.config/fish/completions/tslua.fish

Run as a JSON-over-stdin/stdout server. Used by the TSTL test suite (just tstl-test) to avoid re-launching the binary per test case.

Terminal window
tslua server
tslua server --socket /tmp/tslua.sock
FlagDescription
--socketUnix socket path (default: stdin/stdout)