A TypeScript library for parsing, formatting, and providing type interfaces for Lua and Luau code.
Explore the docs ยป
View Examples ยท Report Bug ยท Request Feature ยท Security ยท Contributing
LuaTS bridges the gap between Lua/Luau and TypeScript ecosystems, allowing developers to leverage type safety while working with Lua codebases. Whether you're developing Roblox games, working with embedded Lua, or maintaining legacy Lua code, LuaTS helps you generate accurate TypeScript definitions for better IDE support, type checking, and developer experience.
- Parse standard Lua and Luau code into Abstract Syntax Trees (AST)
- Convert Luau type declarations into TypeScript interfaces
- Format Lua/Luau code with customizable styling options
- Comprehensive AST manipulation with full type definitions
- Maps Lua types to TypeScript equivalents (
string,number,boolean,nilโnull) - Optional types (
foo: string?โfoo?: string) - Array types (
{string}โstring[]) - Record types (
{[string]: any}โRecord<string, any>) - Function types (
(x: number) -> stringโ(x: number) => string) - Union types (
"GET" | "POST"โ"GET" | "POST") - Method types with automatic
selfparameter removal
- Template string interpolation with backtick support
- Continue statements with proper loop context validation
- Reserved keywords as property names (
type,export,function,local) - Comment preservation and JSDoc conversion
- Multi-line comment support (
--[[ ]]โ/** */)
- Component-based lexer system with specialized tokenizers
- Plugin system for custom type transformations
- Extensible tokenizer architecture for easy feature additions
- Clean separation of concerns across all modules
- CLI tool with file watching and batch processing
- Configuration file support (
luats.config.json) - Programmatic API with comprehensive options
- Error handling and validation with detailed diagnostics
# Convert single files luats convert file.lua -o file.d.ts # Batch process directories luats convert-dir src/lua -o src/types # Watch mode for development luats convert-dir src/lua -o src/types --watch # Validate syntax luats validate file.lua# Using bun bun add luats # Using npm npm install luats # Using yarn yarn add luatsimport { generateTypes } from 'luats'; const luauCode = ` type Vector3 = { x: number, y: number, z: number } type Player = { name: string, position: Vector3, health: number, inventory?: {[string]: number} } `; const tsCode = generateTypes(luauCode); console.log(tsCode);Output:
interface Vector3 { x: number; y: number; z: number; } interface Player { name: string; position: Vector3; health: number; inventory?: Record<string, number>; }import { generateTypesWithPlugins } from 'luats'; const customPlugin = { name: 'ReadonlyPlugin', description: 'Makes all properties readonly', transformType: (luauType, tsType) => tsType, postProcess: (code) => code.replace(/(\w+):/g, 'readonly $1:') }; const tsCode = await generateTypesWithPlugins( luauCode, { useUnknown: true }, [customPlugin] );import { parseLuau, formatLua, LuaFormatter } from 'luats'; // Parse Luau code const ast = parseLuau(` local function greet(name: string): string return "Hello, " .. name end `); // Format with custom options const formatter = new LuaFormatter({ indentSize: 4, insertSpaceAroundOperators: true }); const formatted = formatter.format(ast);- ๐ฎ Roblox Development: Generate TypeScript definitions from Luau types for better IDE support
- ๐ฏ Game Development: Maintain type safety when interfacing with Lua-based game engines
- ๐ Legacy Code Integration: Add TypeScript types to existing Lua codebases
- ๐ API Type Definitions: Generate TypeScript types for Lua APIs
- ๐ ๏ธ Development Tools: Build better tooling for Lua/TypeScript interoperability
Visit luats.lol for comprehensive documentation including:
# Convert a single file npx luats convert src/player.lua -o src/player.d.ts # Convert a directory npx luats convert-dir src/lua -o src/types # Validate syntax npx luats validate src/player.lua # Watch for changes npx luats convert-dir src/lua -o src/types --watchCreate luats.config.json:
{ "outDir": "./types", "include": ["**/*.lua", "**/*.luau"], "exclude": ["**/node_modules/**"], "preserveComments": true, "commentStyle": "jsdoc", "typeGeneratorOptions": { "useUnknown": true, "interfacePrefix": "", "includeSemicolons": true }, "plugins": ["./plugins/my-plugin.js"] }Create custom plugins to extend LuaTS functionality:
import { Plugin } from 'luats'; const MyPlugin: Plugin = { name: 'MyPlugin', description: 'Custom type transformations', transformType: (luauType, tsType) => { if (tsType === 'number') return 'SafeNumber'; return tsType; }, postProcess: (code) => { return `// Generated with MyPlugin\n${code}`; } };LuaTS features a modular architecture:
src/parsers/- Lua and Luau parsers with AST generationsrc/clients/- Lexer and formatter with component-based designsrc/generators/- TypeScript and Markdown generatorssrc/plugins/- Plugin system with transformation hookssrc/cli/- Command-line interface with configuration supportsrc/types.ts- Comprehensive AST type definitions
Contributions are welcome! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with โค๏ธ by the LuaTS team