77 lines
8.0 KiB
Markdown
77 lines
8.0 KiB
Markdown
# Changelog
|
||
|
||
All notable changes to `ts2lua-unreal` will be documented in this file.
|
||
|
||
The format is based on [Semantic Versioning](https://semver.org/).
|
||
|
||
## [0.3.0] - 2026-11-30
|
||
|
||
### Added
|
||
- **自定义模块化与单文件运行时热更系统**:
|
||
- 新增基础运行时 [runtime/Lib/Module.lua](runtime/Lib/Module.lua)(定义 `_G.__MODULE__`,支持隔离 `_ENV`、单文件 `Reimport`/`ReimportSafely`、下游局部 upvalue `UpdateImports()` 刷新、循环依赖等待回填、Barrel 再导出级联、`OnImport`/`OnReimport`/`OnDepModuleReimported` 生命周期钩子、自定义 File/Chunk/Pattern Loader,并默认只读复用 `package.searchers` 无入侵适配 UE/UnLua 与离线 Lua 5.4)。
|
||
- 新增热更类运行时 [runtime/Lib/Class.lua](runtime/Lib/Class.lua)(定义扁平全局函数 `_G.__TS__DefineClass`,零表查询开销,复用 `cls` 与 `cls.prototype` 并在热更时清理已删除方法,100% 兼容 TSTL `lualib_bundle` 的 `__TS__New`/`__TS__ClassExtends`/`__TS__InstanceOf`)。
|
||
- 新增全局类型声明 [types/module.d.ts](types/module.d.ts)(通过 [types/unlua.d.ts](types/unlua.d.ts) 自动引用,无需业务修改 `tsconfig.json`)。
|
||
- 新增编译器转换模块 [src/plugin/module-transform.ts](src/plugin/module-transform.ts):
|
||
- 项目内 TS `import` / `export ... from` 自动转换为 `__MODULE__.Import("...", __module)` 与 `__module.UpdateImports()`;
|
||
- 常规 TS 模块导出写入 `__module.env`(`local ____exports = __module.env`),实时同步 `export let`;
|
||
- 顶层纯 TS 类编译为 `__TS__DefineClass("Name", __module)` 并按需剔除 `lualib_bundle.__TS__Class` 依赖;
|
||
- 支持 `/** @module_data */` 顶层状态跨热更保留(带 `__has__` 哨兵,兼顾 `nil` 值与热更新增变量初值);
|
||
- 原生插件与 UnLua 内置脚本(如 `const cjson = require("cjson")`、`require("UnLua.*")`)保持原生 `require` 且自动免除 TSTL 100000 路径解析报错;
|
||
- 通过 `beforeEmit` 自动产出 `Lib/Module.lua` 与 `Lib/Class.lua`。
|
||
- 插件升级为工厂导出,支持配置项:`moduleSystem?: "hot-reload" | "standard"`(默认 `"hot-reload"`)、`emitRuntime?: boolean`(默认 `true`)、`runtimeDir?: string`(默认 `"Lib"`)。
|
||
- 新增诊断码 `90201 InvalidModuleDataUsage` 与 `90202 ForbiddenExportEqualsInHotReload`。
|
||
- 新增 [test/hot-reload.test.mjs](test/hot-reload.test.mjs) 端到端测试套件(含真实 Lua 5.4 运行时热更、类继承、`@module_data`、Barrel 级联、循环依赖与异常边界测试)。
|
||
|
||
## [0.2.2] - 2026-11-29
|
||
|
||
### Fixed
|
||
- **修复可选链(`a?.b?.c`)触发插件崩溃**:TSTL 转译可选链时会合成无 `SourceFile` / 无 `parent` 的临时 `Identifier` 节点;为 `tryTransformUnLuaSelfClassIdentifier`、`hasAllowTryComment` 与 `arguments` 校验补齐空值保护。
|
||
- **修复 `@unlua` 类静态方法 `self` 参数不匹配 Bug**:移除 `methodHasSelfParam` 中无条件剔除 `static` 方法 `self` 的错误逻辑,使其与 TSTL 调用侧的冒号调用(`ClassName:StaticMethod(...)`)一致,并支持 `this: void`、`/** @noSelf */` 与 `/** @noSelfInFile */` 点号调用;同时在 `super.Method(...)` 调用 `@unlua` 父类方法时尊重目标方法的 `@noSelf` 声明。
|
||
- **修复 `@unlua` 类方法解构参数未展开 Bug**:完整支持对象解构、数组解构、重命名、嵌套解构、默认值与剩余元素(`...rest`)展开。
|
||
- **修复混合默认导入与纯类型命名导入(`import Base, { type BaseCfg } from "./Base"`)生成 `.default` 的 Bug**:当命名导入全为编译期擦除类型时,仍直接生成 `local Base = require("...")`。
|
||
|
||
### Added
|
||
- **编译期宏 `UnLua.Delegate(target, callback)`**:在 [types/unlua.d.ts](types/unlua.d.ts) 中声明并在插件编译期直接内联为 `{ target, callback }`,用于类型安全且零开销地调用 `K2_SetTimerDelegate` / `LoadAsset` / `BindToAnimationFinished` 等接收 `UE.FScriptDelegate` 参数的 UE API;同时在编译期拦截对 `UnLua.Delegate` 传入箭头函数或匿名函数(`90107`)。
|
||
- **补齐 UnLua 全局运行时类型声明**:新增 `UnLua.Log` / `LogWarn` / `LogError`、`UnLua.Input`(`BindKey` / `BindAction` / `BindAxis`)及 `UnLua.EnhancedInput`(`BindAction`),并让 `UE.TArray<T>` / `UE.TMap<K, V>` 继承 `LuaPairsIterable`,支持 `for (const [k, v] of container)` 直接编译为 Lua 原生 `pairs()` 遍历。
|
||
- **增强编译期约束检查**:新增拦截 `BigInt` 字面量(`123n`)、`new UE.AActor()` / `new UE.UObject()` 误实例化,以及继承独立 `@unlua` 类时漏标 `@unlua` 的防呆检查。
|
||
- **扩展插件测试套件**:[test/plugin.test.mjs](test/plugin.test.mjs) 增至 23 组测试,并结合本机 `lua5.4` 执行编译产物验证运行时语义。
|
||
|
||
## [0.2.1] - 2026-11-29
|
||
|
||
### Fixed
|
||
- 修正 [types/unlua.d.ts](types/unlua.d.ts) 中 `UE.TArray` 与 UnLua `LuaLib_Array.cpp` 不一致的两处签名:
|
||
- `RemoveItem(item: T): number`(实际返回移除元素数量 `int32`,而非 `boolean`)。
|
||
- `GetData(): unknown`(无参调用,传参会在运行时触发 `luaL_error`)。
|
||
|
||
### Added
|
||
- 在 [types/unlua.d.ts](types/unlua.d.ts) 中补充 UnLua 原生基础类型描述符 Token(`UE.int8`~`UE.uint64`、`UE.float`、`UE.double`、`UE.bool`、`UE.FName`、`UE.FString`),支持直接使用 `UE.TArray(UE.int32)` / `UE.TMap(UE.FString, UE.float)` 构造原生类型容器。
|
||
|
||
## [0.2.0] - 2026-11-29
|
||
|
||
### Changed
|
||
- **拆分精简 [types/unlua.d.ts](types/unlua.d.ts)**:移除所有 UE 引擎反射类声明(`UObject`/`AActor`/`UWorld`/`FVector`/`UKismetSystemLibrary` 等),仅保留 UE 反射无法自动生成的零冲突核心运行时层(`@unlua` 装饰器、`UnLua` 全局模块、`TArray`/`TMap`/`TSet`、智能指针模板别名、`FScriptDelegate`/`FMulticastScriptDelegate`/`FMulticastSparseDelegate` 以及 `UE.NewObject`/`LoadClass`/`LoadObject`),彻底避免与 UE 项目自动生成的反射 `.d.ts` 冲突。
|
||
|
||
### Removed
|
||
- 移除仓库内置的 `examples/` 示例工程、`examples/types/demo.d.ts` 及 `build:examples` / `watch:examples` 脚本;插件自动化测试保留在 [test/plugin.test.mjs](test/plugin.test.mjs) 中使用内存虚拟声明运行。
|
||
|
||
## [0.1.0] - 2026-11-29
|
||
|
||
### Added
|
||
- **规范与接入文档**:
|
||
- [docs/ts-unlua-spec.md](docs/ts-unlua-spec.md):面向 UE 5.8 + UnLua 2.3.6(Lua 5.4)的 TypeScript 开发与语言约束规范。
|
||
- [docs/integration-guide.md](docs/integration-guide.md):UE 项目接入、错误码速查、版本升级与本地 `npm link` 联调手册。
|
||
- [docs/ai-rules-template.md](docs/ai-rules-template.md):可直接复用的业务项目规则模板。
|
||
- **UnLua TSTL 编译器插件 (`src/plugin/`)**:
|
||
- 编译期拦截全部禁用语言特性(`90001`~`90016`)与 `@unlua` 绑定类专项约束(`90101`~`90110`,含继承 `UE.UObject` 漏标 `@unlua` 防呆)。
|
||
- `@unlua` 类原生 UnLua 代码生成:`local ClassName = UnLua.Class(...)`、`function ClassName.Method(self, ...)`、`return ClassName`,消除 `____exports` / `__TS__Class` / `__TS__Decorate` 垫片。
|
||
- 精确 `super.Method(...)` 映射(UE 原生基类 -> `self.Overridden.Method(self, ...)`;`@unlua` TS 父类 -> `BaseClass.Method(self, ...)`)。
|
||
- `@unlua` 默认导入直连优化(`import Base from "./Base"` -> `local Base = require("...")`,不生成 `.default`)。
|
||
- 面向大项目(3000~5000+ 文件)的 `WeakMap` 类型与文件名缓存优化。
|
||
- **包导出与 CLI**:
|
||
- 暴露 `ts2lua-unreal`、`ts2lua-unreal/tsconfig.base.json`、`ts2lua-unreal/types/unlua.d.ts` 及全部文档导出。
|
||
- 提供 `ts2lua-unreal build` / `watch` / `info` CLI 命令与 `prepare` 自动构建脚本,支持通过 npm Git Tag 依赖无缝接入任意 UE 项目。
|
||
- **基础类型、示例与测试**:
|
||
- [types/unlua.d.ts](types/unlua.d.ts):全局 `@unlua` 装饰器及 UnLua/UE 核心基础类型声明。
|
||
- `examples/`:还原 `UnrealLuaDemo` 的端到端 TS -> UnLua 示例工程。
|
||
- `test/plugin.test.mjs`:16 组正反用例自动化测试套件。
|