|
| 1 | +<div align="center"> |
| 2 | + <img src="assets/logo.png" alt="LuaTS Logo" width="300" /> |
| 3 | +</div> |
| 4 | + |
| 5 | +<div align="center"> |
| 6 | + |
| 7 | +[](https://www.npmjs.org/package/luats) |
| 8 | +[](https://github.com/codemeapixel/luats/actions) |
| 9 | +[](https://npm-stat.com/charts.html?package=luats) |
| 10 | +[](https://github.com/codemeapixel/luats/blob/main/LICENSE) |
| 11 | +[](https://makeapullrequest.com) |
| 12 | + |
| 13 | +</div> |
| 14 | + |
| 15 | +<p align="center"> |
| 16 | + <b>A TypeScript library for parsing, formatting, and providing type interfaces for Lua and Luau code.</b> |
| 17 | + <br> |
| 18 | + <a href="https://luats.codemeapixel.dev"><strong>Explore the docs »</strong></a> |
| 19 | + <br> |
| 20 | + <br> |
| 21 | + <a href="https://luats.codemeapixel.dev/examples">View Examples</a> |
| 22 | + · |
| 23 | + <a href="https://github.com/codemeapixel/luats/issues/new?labels=bug&template=bug_report.md">Report Bug</a> |
| 24 | + · |
| 25 | + <a href="https://github.com/codemeapixel/luats/issues/new?labels=enhancement&template=feature_request.md">Request Feature</a> |
| 26 | + · |
| 27 | + <a href="https://github.com/codemeapixel/luats/security/policy">Security</a> |
| 28 | +</p> |
| 29 | + |
| 30 | +## 🌟 What is LuaTS? |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +## ✨ Features |
| 35 | + |
| 36 | +- 🔁 **Converts Lua/Luau type declarations into TypeScript interfaces** |
| 37 | +- 🧠 **Maps Lua types to TypeScript equivalents** (`string`, `number`, etc.) |
| 38 | +- ❓ **Supports optional types** (`foo: string?` → `foo?: string`) |
| 39 | +- 🔧 **Handles table types** (`{string}` → `string[]` or `Record`) |
| 40 | +- ➡️ **Converts Luau function types to arrow functions in TS** |
| 41 | +- 📄 **Preserves comments and maps them to JSDoc format** |
| 42 | +- 📁 **Supports single-file or batch directory conversion** |
| 43 | +- 🛠 **Includes a CLI tool**: |
| 44 | + - `--out` / `-o` for output path |
| 45 | + - `--watch` for live file watching |
| 46 | + - `--silent` / `--verbose` modes |
| 47 | +- 🧪 **Validates syntax and reports conversion errors** |
| 48 | +- 🔌 **Optional config file** (`luats.config.json`) |
| 49 | +- 🔄 **Merges overlapping types or handles shared structures** |
| 50 | +- 📦 **Programmatic API** (`convertLuaToTS(code: string, options?)`) |
| 51 | +- 🧩 **Plugin hook system for custom transforms** (planned) |
| 52 | +- 🧠 **(Optional) Inference for inline tables to generate interfaces** |
| 53 | +- 📜 **Fully typed** (written in TS) with exported definitions |
| 54 | +- 🧪 **Test suite with snapshot/fixture testing** |
| 55 | + |
| 56 | +## 📦 Installation |
| 57 | + |
| 58 | +```bash |
| 59 | +# Using npm |
| 60 | +npm install luats |
| 61 | + |
| 62 | +# Using yarn |
| 63 | +yarn add luats |
| 64 | + |
| 65 | +# Using bun |
| 66 | +bun add luats |
| 67 | +``` |
| 68 | + |
| 69 | +## 🚀 Quick Start |
| 70 | + |
| 71 | +```typescript |
| 72 | +import { LuaParser, LuaFormatter, TypeGenerator } from 'luats'; |
| 73 | + |
| 74 | +// Parse Lua code |
| 75 | +const parser = new LuaParser(); |
| 76 | +const ast = parser.parse(` |
| 77 | + local function greet(name) |
| 78 | + return "Hello, " .. name |
| 79 | + end |
| 80 | +`); |
| 81 | + |
| 82 | +// Generate TypeScript from Luau types |
| 83 | +const typeGen = new TypeGenerator(); |
| 84 | +const tsCode = typeGen.generateTypeScript(` |
| 85 | + type Vector3 = { |
| 86 | + x: number, |
| 87 | + y: number, |
| 88 | + z: number |
| 89 | + } |
| 90 | +`); |
| 91 | + |
| 92 | +console.log(tsCode); |
| 93 | +// Output: interface Vector3 { x: number; y: number; z: number; } |
| 94 | +``` |
| 95 | + |
| 96 | +## 💡 Use Cases |
| 97 | + |
| 98 | +- **Roblox Development**: Generate TypeScript definitions from Luau types for better IDE support |
| 99 | +- **Game Development**: Maintain type safety when interfacing with Lua-based game engines |
| 100 | +- **Legacy Code Integration**: Add TypeScript types to existing Lua codebases |
| 101 | +- **API Type Definitions**: Generate TypeScript types for Lua APIs |
| 102 | +- **Development Tools**: Build better tooling for Lua/TypeScript interoperability |
| 103 | + |
| 104 | +📚 **[Read the full documentation](https://luats.codemeapixel.dev)** for comprehensive guides, API reference, and examples. |
| 105 | + |
| 106 | +## 📖 Documentation |
| 107 | + |
| 108 | +Visit **[luats.codemeapixel.dev](https://luats.codemeapixel.dev)** for comprehensive documentation including: |
| 109 | + |
| 110 | +- [Getting Started Guide](https://luats.codemeapixel.dev/getting-started) |
| 111 | +- [API Reference](https://luats.codemeapixel.dev/api-reference) |
| 112 | +- [CLI Usage](https://luats.codemeapixel.dev/cli) |
| 113 | +- [Plugin System](https://luats.codemeapixel.dev/plugins) |
| 114 | +- [Examples](https://luats.codemeapixel.dev/examples) |
| 115 | +- [Contributing Guide](https://luats.codemeapixel.dev/contributing) |
| 116 | + |
| 117 | +## 🤝 Contributing |
| 118 | + |
| 119 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 120 | + |
| 121 | +1. Fork the repository |
| 122 | +2. Create your feature branch (`git checkout -b feature/amazing-feature`) |
| 123 | +3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 124 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 125 | +5. Open a Pull Request |
| 126 | + |
| 127 | +See the [Contributing Guide](https://luats.codemeapixel.dev/contributing) for more information. |
| 128 | + |
| 129 | +## 📄 License |
| 130 | + |
| 131 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
0 commit comments