A typed superset of Lua with gradual typing, inspired by TypeScript's approach to JavaScript.
TypedLua brings static type checking to Lua while maintaining its simplicity and allowing gradual adoption. Write type-safe Lua code that compiles to plain Lua, with zero runtime overhead.
- Gradual Typing - Add types at your own pace, from none to full coverage
- TypeScript-Inspired - Familiar syntax for developers coming from TypeScript
- Zero Runtime Cost - Types are erased at compile time
- Lua Compatibility - Compiles to clean, readable Lua (5.1-5.4)
- Rich Type System - Interfaces, unions, generics, and more
- Optional Features - Enable OOP, functional programming, or decorators as needed
- LSP Support - Full language server with autocomplete, diagnostics, and more
Current Status: Beta
The compiler is feature-complete and ready for testing:
- ✅ Full lexer with 40+ token types, template strings, string interning
- ✅ Complete parser with 15 statement types, 13 expression kinds, error recovery
- ✅ Type checker with generics, narrowing, 12 utility types, decorators
- ✅ Code generator targeting Lua 5.1-5.4 with source maps and bundling
- ✅ CLI with watch mode, parallel compilation, configuration files
- ✅ LSP with hover, completion, go-to-definition, references, rename, formatting
- ✅ VS Code extension
Remaining Work: Polish & Release (In Progress)
# Build from source
git clone https://github.com/forge18/typed-lua
cd typed-lua
cargo build --release
# The binary will be at target/release/typedlua-- Variable declarations with types
const PI: number = 3.14159
local radius: number = 5
-- Interfaces for table shapes
interface Point {
x: number,
y: number
}
-- Functions with type signatures
function calculateArea(r: number): number
return PI * r * r
end
-- Type inference
const area = calculateArea(radius) -- inferred as number
print("Area:", area)local PI = 3.14159
local radius = 5
local function calculateArea(r)
return PI * r * r
end
local area = calculateArea(radius)
print("Area:", area)Create a tlconfig.yaml in your project root:
compilerOptions:
target: "5.4" # Lua version: 5.1, 5.2, 5.3, 5.4
strictNullChecks: true # Enforce null safety
enableOop: true # Enable class syntax
enableFp: true # Enable pattern matching, pipe operators
enableDecorators: true # Enable decorator syntax
outDir: "dist" # Output directory
sourceMap: true # Generate source maps
include:
- "src/**/*.tl"
exclude:
- "**/node_modules/**"
- "**/dist/**"TypedLua is built in Rust with a focus on modularity and testability:
typedlua/
├── crates/
│ ├── typedlua-core/ # Compiler core (lexer, parser, type checker, codegen)
│ ├── typedlua-cli/ # Command-line interface
│ └── typedlua-lsp/ # Language Server Protocol implementation
Design Principles:
- Dependency injection for testability
- Trait-based abstractions for flexibility
- Comprehensive error handling with detailed diagnostics
- Zero runtime overhead - all types erased at compile time
- Rust 1.70+
- Cargo
# Build all crates
cargo build
# Run tests
cargo test
# Run linter
cargo clippy
# Format code
cargo fmt# Run all tests
cargo test --all
# Run tests for specific crate
cargo test -p typedlua-core
# Run with coverage
cargo tarpaulin --all-features --workspaceTypedLua provides a rich type system inspired by TypeScript:
nil,boolean,number,integer,stringunknown(type-safe, must narrow before use)never(for exhaustiveness checking)void(for functions with no return)
- Arrays:
number[]orArray<number> - Tuples:
[string, number] - Functions:
(x: number) -> boolean - Unions:
string | number - Interfaces: table shapes only
- Type aliases: everything except table shapes
See docs/designs/TypedLua-Design.md for complete type system documentation.
TypedLua includes powerful OOP features for building robust applications:
overridekeyword - Explicit method overriding with compile-time validationfinalkeyword - Prevent inheritance and method overriding- Classes, interfaces, and inheritance
- Access modifiers (public, private, protected)
- Decorators and metadata
- Pattern matching and destructuring
See docs/LANGUAGE_FEATURES.md for detailed documentation and examples.
- Phase 0: Foundation - Project setup, DI, configuration, CI/CD
- Phase 1: Lexer & Parser - Tokenization and AST construction
- Phase 2: Type System - Type checking and inference
- Phase 3: Code Generation - Lua output with source maps
- Phase 4: CLI - Command-line interface and watch mode
- Phase 5: Advanced Features - Generics, utility types, narrowing
- Phase 6: OOP - Classes, inheritance, access modifiers
- Phase 7: FP - Pattern matching, destructuring, pipe operators
- Phase 8: Decorators - Decorator syntax and built-ins
- Phase 9: LSP - Full language server with VS Code extension
- Phase 10: Standard Library - Type definitions for Lua stdlib
- Phase 11: Polish - Performance optimization, incremental compilation, error messages
- Phase 12: Release - v1.0.0 launch
See docs/ARCHITECTURE.md for detailed implementation status.
TypedLua is under active development. Contributions are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure:
- All tests pass (
cargo test) - Code is formatted (
cargo fmt) - No clippy warnings (
cargo clippy)
MIT License - see LICENSE for details.
- Inspired by TypeScript and Teal
- Built with Rust for performance and safety
- Uses Tower LSP for language server implementation
Status: 🚀 Beta - Core Features Complete, Polishing for v1.0
Built with ❤️ by the TypedLua team