175 lines
5.5 KiB
TypeScript
175 lines
5.5 KiB
TypeScript
/**
|
||||
|
|
* ts2lua-unreal 自定义模块化与单文件运行时热更系统类型声明。
|
|||
|
|
* 对应运行时基础库:`Lib/Module.lua`(_G.__MODULE__)与 `Lib/Class.lua`(_G.__TS__DefineClass)。
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
declare namespace __MODULE__ {
|
|||
|
|
interface Module extends Record<string, any> {
|
|||
|
|
__module: ModuleMeta;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
type ModuleChunkFunction = (this: void) => void;
|
|||
|
|
|
|||
|
|
type LoadModuleFileFunc = (
|
|||
|
|
this: void,
|
|||
|
|
modname: string
|
|||
|
|
) => LuaMultiReturn<[string | undefined, string, string | undefined]>;
|
|||
|
|
|
|||
|
|
type LoadModuleChunkFunc = (
|
|||
|
|
this: void,
|
|||
|
|
modname: string,
|
|||
|
|
env: any
|
|||
|
|
) => LuaMultiReturn<[ModuleChunkFunction | undefined, string, string | undefined]>;
|
|||
|
|
|
|||
|
|
interface ModuleMeta {
|
|||
|
|
name: string;
|
|||
|
|
imports: Record<string, boolean>;
|
|||
|
|
env: Module;
|
|||
|
|
|
|||
|
|
/** 该模块当前是否处于 Reimport 流程中(由模块系统维护,业务只读)。 */
|
|||
|
|
readonly reimporting?: boolean;
|
|||
|
|
|
|||
|
|
/** 是否包含再导出(Barrel 模块标记,由编译器自动设置)。 */
|
|||
|
|
hasReexports?: boolean;
|
|||
|
|
|
|||
|
|
filepath?: string;
|
|||
|
|
hash?: string;
|
|||
|
|
|
|||
|
|
modulefunc?: ModuleChunkFunction;
|
|||
|
|
UpdateExports?: (this: void, env: Module) => void;
|
|||
|
|
UpdateImports?: (this: void, env?: Module) => void;
|
|||
|
|
StashData?: (this: void, env: Module, to: Record<string, any>) => void;
|
|||
|
|
RestoreData?: (this: void, env: Module, from: Record<string, any>) => void;
|
|||
|
|
|
|||
|
|
/** 当模块首次加载完成后回调;热更时不会再次回调。 */
|
|||
|
|
OnImport?(this: void): void;
|
|||
|
|
|
|||
|
|
/** 当模块被 Reimport 热更完成后回调;首次加载时不会回调。 */
|
|||
|
|
OnReimport?(this: void): void;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 当本模块直接依赖的某个模块热更完成且本模块 UpdateImports 刷新完毕后回调。
|
|||
|
|
* @param mname 已热更完成的依赖模块全名(如 `"Framework.Log"`)
|
|||
|
|
*/
|
|||
|
|
OnDepModuleReimported?(this: void, mname: string): void;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
interface ModuleConfig {
|
|||
|
|
Errorf?: (this: void, fmt: string, ...args: any[]) => void;
|
|||
|
|
Infof?: (this: void, fmt: string, ...args: any[]) => void;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
interface ModuleProfileConfig {
|
|||
|
|
GetTime?: (this: void) => number;
|
|||
|
|
ProfileBeginSample?: (this: void, key: string) => void;
|
|||
|
|
ProfileEndSample?: (this: void) => void;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 任意模块首次加载完成后的全局回调 */
|
|||
|
|
let OnModuleLoaded: ((this: void, modname: string) => void) | undefined;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function Import<T = Module>(
|
|||
|
|
modname: string,
|
|||
|
|
callerModule?: ModuleMeta,
|
|||
|
|
loadModuleChunk?: LoadModuleChunkFunc
|
|||
|
|
): T;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 重新加载(单文件热更)已加载模块。
|
|||
|
|
* @param pathOrName 以 `@` 开头按模块路径查找,否则按模块全名查找
|
|||
|
|
* @param loadModuleChunk 可选自定义 chunk 加载器
|
|||
|
|
* @noSelf
|
|||
|
|
*/
|
|||
|
|
function Reimport(
|
|||
|
|
pathOrName: string,
|
|||
|
|
loadModuleChunk?: LoadModuleChunkFunc
|
|||
|
|
): LuaMultiReturn<[Module | undefined, string | undefined]>;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 与 Reimport 相同但不抛异常,返回 `(ok, err)`。
|
|||
|
|
* @noSelf
|
|||
|
|
*/
|
|||
|
|
function ReimportSafely(
|
|||
|
|
pathOrName: string,
|
|||
|
|
loadModuleChunk?: LoadModuleChunkFunc
|
|||
|
|
): LuaMultiReturn<[boolean, any]>;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 查询是否处于热更中:不传参查全局,传入 `__module` 仅查当前模块。
|
|||
|
|
* @noSelf
|
|||
|
|
*/
|
|||
|
|
function IsReimporting(meta?: ModuleMeta): boolean;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function GetModuleByName(modname: string): Module | undefined;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function GetModuleByPath(modpath: string): Module | undefined;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function GetAllModulePaths(): Record<string, Module>;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function AllLoadedModules(): Record<string, Module>;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function SetSystemMeta(key: string, value: any): void;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function GetSystemMeta(key: string): any;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function ModuleNameToPath(modname: string): string;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function OnLoadModuleFileDefault(
|
|||
|
|
modname: string
|
|||
|
|
): LuaMultiReturn<[string | undefined, string, string | undefined]>;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function OnLoadModuleChunkDefault(
|
|||
|
|
modname: string,
|
|||
|
|
env: any
|
|||
|
|
): LuaMultiReturn<[ModuleChunkFunction | undefined, string, string | undefined]>;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function LoadModuleFile(
|
|||
|
|
modname: string
|
|||
|
|
): LuaMultiReturn<[string | undefined, string, string | undefined]>;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function LoadModuleChunk(
|
|||
|
|
modname: string,
|
|||
|
|
env: any
|
|||
|
|
): LuaMultiReturn<[ModuleChunkFunction | undefined, string, string | undefined]>;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function LoadModuleChunkFromString(
|
|||
|
|
modname: string,
|
|||
|
|
data: string,
|
|||
|
|
chunkname: string,
|
|||
|
|
env: any
|
|||
|
|
): ModuleChunkFunction;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function RegistryModuleLoader(modpattern: string, loader: LoadModuleChunkFunc): void;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function SetOnLoadModuleFile(func: LoadModuleFileFunc): void;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function SetOnLoadModuleChunk(func: LoadModuleChunkFunc): void;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function Config(args: ModuleConfig): void;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function SetProfile(args: ModuleProfileConfig): void;
|
|||
|
|
|
|||
|
|
/** @noSelf */
|
|||
|
|
function GetImportingStack(maybeLoopPos?: number): string;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/** 当前模块元信息对象(位于模块隔离 _ENV 中,可用于挂载 OnImport / OnReimport / OnDepModuleReimported) */
|
|||
|
|
declare const __module: __MODULE__.ModuleMeta;
|