2026-11-28 16:19:14 +08:00
|
|
|
|
# ts2lua-unreal
|
|
|
|
|
|
|
2026-11-28 22:26:22 +08:00
|
|
|
|
面向 **Unreal Engine 5.8 + UnLua 2.3.6(Lua 5.4)** 的 TypeScript 开发工具链与编译器插件,基于官方 [TypeScriptToLua (TSTL)](https://github.com/TypeScriptToLua/TypeScriptToLua) 插件机制实现(无需 Fork TSTL 源码)。
|
|
|
|
|
|
|
|
|
|
|
|
## 特性概览
|
|
|
|
|
|
|
|
|
|
|
|
- **原生 UnLua 代码生成**:通过全局免 `import` 编译期装饰器 `@unlua` 标记绑定类,直接输出 `local M = UnLua.Class(...)`、`function M.Method(self, ...)` 与 `return M`,零 `__TS__Class` / `__TS__Decorate` / `____exports` 垫片污染。
|
|
|
|
|
|
- **精确的 `super` 映射**:
|
|
|
|
|
|
- 继承 UE C++/蓝图原生基类 -> `self.Overridden.Method(self, ...)`
|
|
|
|
|
|
- 继承另一个 `@unlua` TS 绑定类 -> `BaseClass.Method(self, ...)`(规避多层继承 `self.Super` 递归坑)
|
|
|
|
|
|
- **编译期强约束(Fail Fast)**:在 TSTL AST 阶段直接阻断 `get/set` 访问器、`async/await`/`Promise`、`try/catch/throw`、`RegExp`/`Map`/`Set`/`Proxy`/`Symbol`、普通运行时 `enum`、`@unlua` 类 `constructor`/字段初始化器/`new` 实例化、UE Delegate 匿名函数回调、`UObject` 的 `instanceof`/`delete`/对象展开以及继承 `UE.UObject` 漏标 `@unlua` 等问题。
|
|
|
|
|
|
- **面向大型项目(3000~5000+ 文件)优化**:插件预编译为 JS、复用 TSTL 单次 AST 遍历、`WeakMap` 缓存类型查询、`skipLibCheck: true` 与增量 Watch 模式支持。
|
|
|
|
|
|
|
2026-11-29 00:31:10 +08:00
|
|
|
|
## 在 UE 项目中接入(快速预览)
|
2026-11-28 22:26:22 +08:00
|
|
|
|
|
2026-11-29 00:31:10 +08:00
|
|
|
|
在 UE 项目的 `TypeScript/package.json` 中通过 Git Tag 依赖接入:
|
|
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
|
{
|
|
|
|
|
|
"scripts": {
|
|
|
|
|
|
"build": "ts2lua-unreal build",
|
|
|
|
|
|
"watch": "ts2lua-unreal watch",
|
|
|
|
|
|
"info": "ts2lua-unreal info"
|
|
|
|
|
|
},
|
|
|
|
|
|
"devDependencies": {
|
|
|
|
|
|
"ts2lua-unreal": "git+ssh://git@106.55.3.105:20022/szy73711/ts2lua-unreal.git#v0.1.0"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-28 22:26:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-11-29 00:31:10 +08:00
|
|
|
|
`TypeScript/tsconfig.json` 直接继承内置基线配置:
|
|
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
|
{
|
|
|
|
|
|
"extends": "ts2lua-unreal/tsconfig.base.json",
|
|
|
|
|
|
"compilerOptions": {
|
|
|
|
|
|
"rootDir": "src",
|
|
|
|
|
|
"outDir": "../Content/Script"
|
|
|
|
|
|
},
|
|
|
|
|
|
"include": [
|
|
|
|
|
|
"src/**/*.ts",
|
|
|
|
|
|
"types/**/*.d.ts",
|
|
|
|
|
|
"node_modules/ts2lua-unreal/types/unlua.d.ts"
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
> 完整的接入步骤、错误码速查表、版本升级与本地 `npm link` 联调套路,请查阅 **[UE 项目接入与迭代升级指南](docs/integration-guide.md)**。
|
|
|
|
|
|
|
|
|
|
|
|
## 文档索引
|
|
|
|
|
|
|
|
|
|
|
|
- [UE 项目接入与迭代升级指南](docs/integration-guide.md)(首次接入、错误码速查、升级/回滚与 `npm link` 联调)
|
|
|
|
|
|
- [TypeScript to UnLua 开发与语言约束规范](docs/ts-unlua-spec.md)(完整语言子集约束与原理说明)
|
|
|
|
|
|
- [业务项目开发规则模板](docs/ai-rules-template.md)(可直接复制到 UE 项目的 `AGENTS.md` / 团队规范)
|
|
|
|
|
|
- [版本变更日志](CHANGELOG.md)
|
|
|
|
|
|
|
|
|
|
|
|
## 本仓库开发命令
|
2026-11-28 22:26:22 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
# 安装依赖
|
|
|
|
|
|
npm install
|
|
|
|
|
|
|
|
|
|
|
|
# 构建插件并运行全部自动化测试
|
|
|
|
|
|
npm test
|
|
|
|
|
|
|
|
|
|
|
|
# 编译示例工程(输出至 examples/out/)
|
|
|
|
|
|
npm run build:examples
|
|
|
|
|
|
|
2026-11-29 00:31:10 +08:00
|
|
|
|
# 增量监听模式
|
2026-11-28 22:26:22 +08:00
|
|
|
|
npm run watch:examples
|
|
|
|
|
|
```
|