Skip to main content

TypeScriptToLua

Write Lua with TypeScript

// Give points to all friends around the target position
function onAbilityCast(caster: Unit, targetPos: Vector) {
const units = findUnitsInRadius(targetPos, 500);

const friends = units.filter(unit => caster.isFriend(unit));

for (const friend of friends) {
friend.givePoints(50);
}

}
-- Give points to all friends around the target position
function onAbilityCast(caster, targetPos)
local units = findUnitsInRadius(targetPos, 500)
local friends = __TS__ArrayFilter(
units,
function(____, unit) return caster:isFriend(unit) end
)
for ____, friend in ipairs(friends) do
friend:givePoints(50)
end
end

Declare and use existing APIs

This project is useful in any environment where Lua code is accepted, with the powerful option of declaring types for any existing API using TypeScript declaration files.

Type Safety

Static types can ease the mental burden of writing programs, by automatically tracking information the programmer would otherwise have to track mentally in some fashion. Types serve as documentation for yourself and other programmers and provide a check that tells you what terms make sense to write.

IDE Support

Types enable Lua developers to use highly-productive development tools and practices like static checking and code refactoring when developing Lua applications. TypeScript extensions are available for many text editors.

Getting started

Getting started with TSTL is easy. Simply install "typescript-to-lua" from npm:

$ npm install -D typescript typescript-to-lua

You can now run tstl via command line, similar to tsc

$ npx tstl

For more information, see the getting started page.