release: v0.3.0 add single-file hot-reload module system (Lib/Module.lua & Lib/Class.lua)
This commit is contained in:
1 parent
cb1539d738
commit
b1a53d8660
19 files changed
+2954
-13
No files matched your search
@@ -269,9 +269,12 @@ StartCoroutine(this, () => {
|
||||
});
|
||||
```
|
||||
|
||||
### 5.6 热重载(Hot Reload)友好约定
|
||||
- 禁止在模块顶层把其他模块的方法赋值缓存到局部变量(如 `const foo = OtherModule.Foo`),否则 `OtherModule` 热重载后缓存的仍是旧函数闭包。
|
||||
- 禁止在模块顶层缓存 `UObject` 实例引用(防止关卡切换后造成内存泄漏或野指针)。
|
||||
### 5.6 自定义模块化与单文件热重载(Hot Reload)规范
|
||||
- **基础运行时**:`Lib/Module.lua`(`_G.__MODULE__`)与 `Lib/Class.lua`(扁平全局函数 `_G.__TS__DefineClass`)由编译插件自动输出,启动时通过原生 `require("Lib.Module")` / `require("Lib.Class")` 初始化,不劫持 `_G.require`、不入侵 UnLua 自身脚本。
|
||||
- **依赖导入边界**:项目内 TS 模块之间一律使用标准 ES `import`(编译为 `__MODULE__.Import("...", __module)` + `__module.UpdateImports()`);外部 Lua/C 插件与 UnLua 内置模块继续使用原生 `require("cjson")` / `require("UnLua.*")`。
|
||||
- **模块状态保留**:需要跨单文件热更保留的顶层变量必须标注 `/** @module_data */`(仅支持模块顶层独立标识符,禁用解构);未标注的顶层变量在热更时重置。
|
||||
- **类原型复用**:顶层纯 TS 类自动通过扁平全局函数 `__TS__DefineClass("Name", __module)` 定义,热更时原地复用 `cls` 与 `cls.prototype` 并清理已删除方法,保证既有实例与子类继承链无缝生效。
|
||||
- **禁忌**:禁止在模块顶层手工赋值缓存其他模块的方法引用(如 `const foo = OtherModule.Foo`),否则无法被编译器登记到 `UpdateImports()`;禁止在模块顶层缓存 `UObject` 实例引用。
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user