TypeScriptToLua
Write Lua with TypeScript
// TS Declarations type Vector = [number, number, number]; declare class Unit { getLevel(): number; isEnemy(other: Unit): boolean; kill(): void; FindUnitsInRadius(radius: number): Unit[]; }
// TS Source function onSpellStart(caster: Unit, targetLocation: Vector): void { const units = caster.FindUnitsInRadius(event.targetLocation, 500); const enemies = units.filter(unit => event.caster.isEnemy(unit)); for (const enemy of enemies) { enemy.kill(); } }
-- Lua Output function onSpellStart(caster, targetLocation) local units = FindUnitsInRadius(targetLocation, 500); local enemies = __TS__ArrayFilter(units, function(unit) return caster:isEnemy(unit) end); for _, enemy in ipairs(enemies) do do enemy:kill(); end end end
Extend existing APIs
This project is useful in any environment where Lua code is accepted, with the powerful option of simply declaring 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 ‘gradient’ that tells you what terms make sense to write.
IDE Support
Types enable JavaScript developers to use highly-productive development tools and practices like static checking and code refactoring when developing JavaScript applications. TypeScript extensions are available for many text editors.