TypeScriptToLua
raw JSON → 0.0.1 verified Fri May 01 auth: no javascript
A generic TypeScript to Lua transpiler that converts TypeScript code into readable and efficient Lua code. Current stable version is 0.0.1, released as an initial alpha. Development is active on GitHub with regular commits. Key differentiators: allows writing TypeScript for any Lua environment, supports declaring existing Lua APIs via declaration files, and integrates with standard TypeScript tooling.
Common errors
error Error: Cannot find module 'typescript' ↓
cause Missing TypeScript peer dependency.
fix
npm install -D typescript@~4.5.2
error TypeError: transpileString is not a function ↓
cause Incorrect import (wrong way).
fix
Use import { transpileString } from 'typescript-to-lua'
error Error: Lua target must be one of: 5.1, 5.2, 5.3, JIT ↓
cause Invalid luaTarget option.
fix
Set luaTarget to a valid target version.
Warnings
breaking v0.0.1 is an early alpha; API may change without notice. ↓
fix Pin exact version and watch changelog.
gotcha TypeScript features not fully supported; e.g., iterators, generators, async/await are not transpiled. ↓
fix Consult documentation for supported features.
gotcha Lua target version must be specified; default may not match your environment. ↓
fix Set luaTarget option explicitly to '5.1', '5.2', '5.3', or 'JIT'.
gotcha String concatenation with + may produce unexpected results in Lua due to type coercion. ↓
fix Use template literals or explicit toString() calls.
deprecated The `tstl` CLI command is deprecated in favor of programmatic API. ↓
fix Use the JavaScript API or migrate to new CLI if available.
Install
npm install un-typescript-to-lua yarn add un-typescript-to-lua pnpm add un-typescript-to-lua Imports
- transpile wrong
const transpile = require('typescript-to-lua').transpilecorrectimport { transpile } from 'typescript-to-lua' - transpileString wrong
import transpileString from 'typescript-to-lua'correctimport { transpileString } from 'typescript-to-lua' - TranspileOptions wrong
import { TranspileOptions } from 'typescript-to-lua'correctimport type { TranspileOptions } from 'typescript-to-lua' - LuaTarget wrong
import { LuaTarget } from 'tstl'correctimport { LuaTarget } from 'typescript-to-lua' - Compiler wrong
const Compiler = require('tstl').Compilercorrectimport { Compiler } from 'typescript-to-lua'
Quickstart
import { transpileString } from 'typescript-to-lua';
const luaCode = transpileString(`
function greet(name: string): string {
return "Hello, " + name;
}
`, {
luaTarget: '5.3',
});
console.log(luaCode);