CLI Reference
Project compilation
Section titled “Project compilation”tslua -p tsconfig.jsontslua -p tsconfig.json --outdir disttslua -p tsconfig.json --watch| Flag | Description | Default |
|---|---|---|
-p, --project | Path to tsconfig.json | |
--outdir | Output directory for Lua files | stdout |
--luaTarget | Lua target version (JIT, 5.0-5.5, universal) | JIT |
--emitMode | tstl (match TSTL output) or optimized | tstl |
--luaLibImport | How lualib is included: require, inline, none | require |
--luaBundle | Bundle all modules into a single Lua file | |
--luaBundleEntry | Entry point for bundle mode | |
--exportAsGlobal | Strip module wrapper, emit exports as globals | false |
--noImplicitSelf | Default functions to no-self unless annotated | false |
--sourceMap | Generate .lua.map source map files | false |
-w, --watch | Watch for file changes and rebuild | false |
--timing | Print phase timings to stderr | false |
--verbose | Print each output file path | false |
--diagnosticFormat | Diagnostic format: tstl or native | tstl |
--cpuprofile | Write CPU profile to file |
Commands
Section titled “Commands”Transpile TypeScript to Lua. Accepts source via -e flag, positional argument, or stdin.
tslua eval -e 'const greet = (name: string) => `Hello, ${name}!`'greet = function(____, name) return ("Hello, " .. name) .. "!" endLoops and standard library calls are translated idiomatically:
echo 'for (const x of [1, 2, 3]) { console.log(x) }' | tslua evalfor ____, x in ipairs({1, 2, 3}) do print(x)endClasses produce full Lua object setup:
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__ClassDog = __TS__Class()Dog.name = "Dog"function Dog.prototype.____constructor(self, n) self.name = nendfunction Dog.prototype.bark(self) return self.name .. " barks"endThe --trace flag annotates each statement with the TS AST node that produced it:
tslua eval --trace -e 'const x = 1 + 2'--[[trace: KindVariableStatement]]x = 1 + 2| Flag | Description |
|---|---|
-e, --expr | TypeScript source to transpile |
--trace | Emit --[[trace: ...]] comments on each statement |
Print the TypeScript AST tree. Useful for debugging transforms.
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| Flag | Description |
|---|---|
-e, --expr | TypeScript source to parse |
completion
Section titled “completion”Generate shell autocompletion scripts.
# Bashtslua completion bash > /etc/bash_completion.d/tslua
# Zshtslua completion zsh > "${fpath[1]}/_tslua"
# Fishtslua completion fish > ~/.config/fish/completions/tslua.fishserver
Section titled “server”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.
tslua servertslua server --socket /tmp/tslua.sock| Flag | Description |
|---|---|
--socket | Unix socket path (default: stdin/stdout) |