TypeScriptToLua Transpiler

1.34.0 · active · verified Sun Apr 19

TypeScriptToLua (tstl) is a transpiler that converts TypeScript code into Lua. It enables developers to leverage TypeScript's static typing, tooling (like ESLint, Prettier, and VS Code support), and maintainability benefits for projects targeting Lua environments. The current stable version is 1.34.0, and new versions are released regularly, often mirroring TypeScript's own release cadence of roughly every 3 months for major updates, with patch releases as needed. A key differentiator is its ability to generate Lua code compatible with various Lua versions, including a 'universal' target, and its extensive use of TypeScript's type information to produce optimized and portable Lua. It's particularly useful for game development (e.g., Dota 2, Defold, LÖVE 2D, World of Warcraft addons) or any application where Lua scripting is used, allowing for strong type safety and improved development workflows through declaration files for existing Lua APIs.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates setting up `tsconfig.json` for TypeScriptToLua, a simple `main.ts` file, and compiling it to Lua using the `tstl` command. This creates `dist/main.lua`.

{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["esnext"],
    "strict": true,
    "moduleResolution": "node",
    "rootDir": ".",
    "outDir": "./dist"
  },
  "tstl": {
    "luaTarget": "universal",
    "luaLibImport": "require"
  },
  "include": ["src/**/*.ts"]
}

// src/main.ts
function greet(name: string): string {
  return `Hello, ${name}!`;
}

console.log(greet("TypeScriptToLua"));

// package.json (excerpt)
/*
{
  "name": "my-lua-project",
  "version": "1.0.0",
  "devDependencies": {
    "typescript": "^5.0.0",
    "typescript-to-lua": "^1.34.0"
  },
  "scripts": {
    "build": "npx tstl"
  }
}
*/

view raw JSON →