chore: rename runtime Lib/Module.lua & Lib/Class.lua to lowercase lib/module.lua & lib/class.lua (v0.3.1)
This commit is contained in:
1 parent
b1a53d8660
commit
1e2a0b7546
13 files changed
+42
-37
No files matched your search
@@ -0,0 +1,53 @@
|
||||
-- 热更友好的纯 TS 类定义运行时(扁平全局函数,零表查询开销,完全兼容 TSTL lualib_bundle)
|
||||
|
||||
local pairs = pairs
|
||||
local type = type
|
||||
|
||||
local allClassTbl = {}
|
||||
|
||||
local function __TS__DefineClass(name, mod)
|
||||
local modname = mod and mod.name or ""
|
||||
local fullName = modname .. ":" .. name
|
||||
local cls = allClassTbl[fullName]
|
||||
if cls then
|
||||
-- 热更重载时清理原型上已删除的旧方法,保持既有实例与子类继承链的原型表引用不变
|
||||
local modSys = _G.__MODULE__
|
||||
if modSys and modSys.IsReimporting and modSys.IsReimporting(mod) then
|
||||
local proto = cls.prototype
|
||||
if proto then
|
||||
for k, v in pairs(proto) do
|
||||
if k ~= "__index" and k ~= "constructor" and type(v) == "function" then
|
||||
proto[k] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
cls.name = name
|
||||
return cls
|
||||
end
|
||||
|
||||
cls = {
|
||||
__classdefine__ = true,
|
||||
__fullname__ = fullName,
|
||||
name = name,
|
||||
prototype = {},
|
||||
}
|
||||
cls.prototype.__index = cls.prototype
|
||||
cls.prototype.constructor = cls
|
||||
|
||||
allClassTbl[fullName] = cls
|
||||
return cls
|
||||
end
|
||||
|
||||
_G.__TS__DefineClass = __TS__DefineClass
|
||||
|
||||
return {
|
||||
DefineClass = __TS__DefineClass,
|
||||
allClassTbl = allClassTbl,
|
||||
GetClass = function(fullName)
|
||||
return allClassTbl[fullName]
|
||||
end,
|
||||
AllClasses = function()
|
||||
return allClassTbl
|
||||
end,
|
||||
}
|
||||
Reference in new issue
Block a user