Skip to content

Luau2TS/luau2ts

Repository files navigation

luau2ts

luau2ts

A Luau-to-TypeScript compiler for Roblox.

CI codecov npm downloads license node

Why?

roblox-ts compiles TypeScript to Luau so Roblox developers can write strongly-typed game code in TS.

luau2ts is the mirror: it compiles Luau to TypeScript. Use it to migrate an existing Luau codebase to TypeScript, to keep two parallel runtimes in sync, or to run authored Luau through TS-native tooling. Output is idiomatic, readable TS, with optional 1:1 line-mapped source maps and a roblox-ts-compatible emit mode.

Directory and Rojo-project modes also emit .d.ts declaration files alongside each compiled .ts, capturing the inferred shape of each module's exports.

Install

npm install -g luau2ts

Or as a project dependency:

npm install --save-dev luau2ts

Quick start

Compile a single file:

luau2ts foo.luau                 # → stdout
luau2ts foo.luau -o foo.ts       # → foo.ts

Compile every .luau and .lua file in a directory tree:

luau2ts src/ -o out/

Walk a Rojo project file and emit a parallel TypeScript tree:

luau2ts -p default.project.json -o out/

Use it as a library:

import { compile } from 'luau2ts';

const result = await compile(`
  local function greet(name)
    print("Hello, " .. name)
  end
`);

console.log(result.source);
// // Compiled by luau2ts v0.1.0 (do not edit).
// function greet(name) {
//   print(`Hello, ${name}`);
// }

Compatibility

luau2ts ships two emit modes. Switch with --mode <name> or compatMode in the library API.

Mode What it emits Pairs with
rbxts (default) TS that mirrors what roblox-ts accepts as input: new Vector3(...), import { Workspace } from '@rbxts/services', 0-indexed arrays for statically-typed arrays. @rbxts/types, @rbxts/services, @rbxts/promise, the roblox-ts build pipeline.
native TS that imports stdlib helpers from luau2ts/runtime (luaIndex, lualen, pairKeys, multiret, ...) and uses Roblox's native API surface (Vector3.new(...), game:GetService(...), 1-indexed arrays). A host runtime that mirrors Roblox's Luau API surface.

Docs

Full guide and API reference at luau2ts.com.

Highlights:

Contributing

See CONTRIBUTING.md for build / test / release workflow.

License

MIT © Tony Bolivar

About

A Luau-to-TypeScript compiler for Roblox.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors