tslua

module
v0.1.0-dev.71 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT

README

tslua

CI codecov

TypeScript-to-Lua transpiler built on typescript-go. Single binary, no Node runtime required.

Built on the architecture and test suite of TypeScriptToLua. For general TypeScript-to-Lua usage and caveats, see the TSTL docs. Targets LuaJIT and Lua 5.0-5.5.

Docs · Playground · CLI reference

Install

npm i @tslua/cli

Try it

// tslua eval -e
const items = [10, 20, 30];
for (const x of items) { print(x * 2) }

// output:
// items = {10, 20, 30}
// for ____, x in ipairs(items) do
//     print(x * 2)
// end

Why tslua

  • Native Go binary. Uses typescript-go's type checker and AST directly via go:linkname shims, no IPC or JS runtime in the loop.
  • TSTL-compatible. Ports TSTL's transforms and lualib faithfully. Reads the same tsconfig.json options and produces compatible output.
  • TS 7 ready. Built on the compiler that TypeScript is migrating to.
  • Fast. ~6-18ms incremental rebuilds in watch mode. Benchmarks
  • Alternative class styles. tstl (default, TSTL-compatible), inline, luabind, middleclass.

Compatibility

Two verification approaches, both running TSTL's own tests:

  • Jest harness. TSTL's Jest suite runs unmodified, but with tslua's transpiler swapped in via a Unix socket server. 6111 / 6179 tests pass (98.9%).
  • Migrated Go tests. A migration system extracts TSTL's Jest specs and code-generates them into native Go tests. 5656 / 5903 cases migrated (95.8%) across 70 of 71 spec files, with 100% behavioral pass rate on migrated cases. The 247 unmigrated cases use TSTL assertion methods (getMainLuaCodeChunk, getLuaExecutionResult, etc.) not yet supported by the migration script.

What's not done yet

  • Plugins. TSTL's luaPlugins hook system. A Go binary can't load JS transformer plugins; the plugin story needs a different shape.
  • Build modes. --buildMode library not implemented.
  • Diagnostics. Not all TSTL diagnostics are ported, and some differ due to typescript-go's type checker.

Building from source

Requires Go 1.24+, Node 20+, and just.

git clone https://github.com/RealColdFry/tslua
cd tslua
just setup
just build
./tslua eval -e 'print("hello")'

Directories

Path Synopsis
cmd
luabench command
tslua command
tslua-client command
tslua-client: tiny Unix socket client for tslua --server.
tslua-client: tiny Unix socket client for tslua --server.
wasm command
internal
emitpath
Package emitpath computes output file paths for transpiled Lua files.
Package emitpath computes output file paths for transpiled Lua files.
lua
Package lua defines the Lua AST node types used as an intermediate representation between TypeScript AST transformation and Lua source code emission.
Package lua defines the Lua AST node types used as an intermediate representation between TypeScript AST transformation and Lua source code emission.
luabench
Package luabench measures runtime and memory performance of transpiled Lua code.
Package luabench measures runtime and memory performance of transpiled Lua code.
lualib
Lualib bundle builder: transpiles TSTL's lualib TypeScript source into a self-contained lualib_bundle.lua matching TSTL's bundle format.
Lualib bundle builder: transpiles TSTL's lualib TypeScript source into a self-contained lualib_bundle.lua matching TSTL's bundle format.
lualibinfo
Package lualibinfo defines types shared between the lualib and transpiler packages.
Package lualibinfo defines types shared between the lualib and transpiler packages.
luatest
Package luatest provides shared test infrastructure for transpiling TypeScript to Lua and evaluating the result.
Package luatest provides shared test infrastructure for transpiling TypeScript to Lua and evaluating the result.
resolve
Package resolve handles post-transpilation dependency resolution.
Package resolve handles post-transpilation dependency resolution.
sourcemap
Package sourcemap implements V3 source map generation.
Package sourcemap implements V3 source map generation.
transpiler
Validates function context (self/no-self) compatibility on assignments.
Validates function context (self/no-self) compatibility on assignments.
scripts
gen-lualib-features command
Generates per-feature .lua files and module info JSON for the lualib.
Generates per-feature .lua files and module info JSON for the lualib.
tools
gen_shims command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL