chore: upgrade ts2lua-unreal to v0.3.1 with lowercase lib/module.lua & lib/class.lua and commit framework refactor

This commit is contained in:
szy73711 committed 2026-11-30 03:43:42 +08:00
1 parent 783dccf53d
commit 3572f2da43
206 files changed
+14442 -13186

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
local ____exports = __module.env
function __module.UpdateImports()
end
+228
View File
@@ -0,0 +1,228 @@
local ____lualib = require("lualib_bundle")
local __TS__New = ____lualib.__TS__New
local ____exports = __module.env
____exports.LogLevel = {
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4
}
---
-- @noSelf
function ____exports.StringToLogLevel(lv)
if lv == "trace" then
return ____exports.LogLevel.TRACE
end
if lv == "debug" then
return ____exports.LogLevel.DEBUG
end
if lv == "warn" then
return ____exports.LogLevel.WARN
end
if lv == "error" then
return ____exports.LogLevel.ERROR
end
return ____exports.LogLevel.INFO
end
---
-- @noSelf
local function LevelLabel(lv)
if lv == ____exports.LogLevel.TRACE then
return "TRACE"
end
if lv == ____exports.LogLevel.DEBUG then
return "DEBUG"
end
if lv == ____exports.LogLevel.INFO then
return "INFO"
end
if lv == ____exports.LogLevel.WARN then
return "WARN"
end
return "ERROR"
end
---
-- @noSelf
function ____exports.SerializeLogValue(value, depth)
if depth == nil then
depth = 0
end
local t = type(value)
if t == "nil" then
return "nil"
end
if t == "string" then
return string.format("%q", value)
end
if t == "number" or t == "boolean" then
return tostring(value)
end
if t ~= "table" then
return tostring(value)
end
if depth >= 3 then
return "{...}"
end
local parts = {}
for k, v in pairs(value) do
parts[#parts + 1] = string.format(
"%s=%s",
tostring(k),
____exports.SerializeLogValue(v, depth + 1)
)
end
table.sort(parts)
return ("{" .. table.concat(parts, ", ")) .. "}"
end
---
-- @module_data
local defaultLogLevel = ____exports.LogLevel.INFO
---
-- @module_data
local customSink = nil
---
-- @module_data
local allLoggers = {}
---
-- @noSelf
local function DefaultSink(level, moduleName, message)
local line = string.format(
"[%s][%s] %s",
LevelLabel(level),
moduleName,
message
)
if UnLua ~= nil then
if level >= ____exports.LogLevel.ERROR and UnLua.LogError ~= nil then
UnLua.LogError(line)
return
end
if level == ____exports.LogLevel.WARN and UnLua.LogWarn ~= nil then
UnLua.LogWarn(line)
return
end
if UnLua.Log ~= nil then
UnLua.Log(line)
return
end
end
print(line)
end
____exports.LoggerObject = __TS__DefineClass("LoggerObject", __module)
local LoggerObject = ____exports.LoggerObject
LoggerObject.name = "LoggerObject"
function LoggerObject.prototype.____constructor(self, name)
self.debugEnabled = false
self.infoEnabled = false
self.warnEnabled = false
self.errorEnabled = false
self.name = name
self.level = defaultLogLevel
self:UpdateLevelFlags()
end
function LoggerObject.prototype.UpdateLevelFlags(self)
self.debugEnabled = self.level <= ____exports.LogLevel.DEBUG
self.infoEnabled = self.level <= ____exports.LogLevel.INFO
self.warnEnabled = self.level <= ____exports.LogLevel.WARN
self.errorEnabled = self.level <= ____exports.LogLevel.ERROR
end
function LoggerObject.prototype.EmitLog(self, level, msg, data)
if self.level > level then
return
end
local payload = data ~= nil and (msg .. ", ") .. ____exports.SerializeLogValue(data, 0) or msg
local sink = customSink or DefaultSink
sink(level, self.name, payload)
end
function LoggerObject.prototype.Debug(self, msg, data)
self:EmitLog(____exports.LogLevel.DEBUG, msg, data)
end
function LoggerObject.prototype.Info(self, msg, data)
self:EmitLog(____exports.LogLevel.INFO, msg, data)
end
function LoggerObject.prototype.Warn(self, msg, data)
self:EmitLog(____exports.LogLevel.WARN, msg, data)
end
function LoggerObject.prototype.Error(self, msg, data)
self:EmitLog(____exports.LogLevel.ERROR, msg, data)
end
function LoggerObject.prototype.d(self, msg, data)
self:Debug(msg, data)
end
function LoggerObject.prototype.i(self, msg, data)
self:Info(msg, data)
end
function LoggerObject.prototype.w(self, msg, data)
self:Warn(msg, data)
end
function LoggerObject.prototype.e(self, msg, data)
self:Error(msg, data)
end
function LoggerObject.prototype.GetLevel(self)
return self.level
end
function LoggerObject.prototype.SetLevel(self, lv)
self.level = type(lv) == "string" and ____exports.StringToLogLevel(lv) or lv
self:UpdateLevelFlags()
return self
end
---
-- @noSelf
function ____exports.SetLogSink(sink)
customSink = sink
end
---
-- @noSelf
function ____exports.SetDefaultLogLevel(lv)
defaultLogLevel = lv
end
---
-- @noSelf
function ____exports.SetAllLoggersLevel(lv)
for _, logger in pairs(allLoggers) do
if logger ~= nil then
logger:SetLevel(lv)
end
end
end
---
-- @noSelf
function ____exports.Logger(name)
local logger = allLoggers[name]
if logger == nil then
logger = __TS__New(____exports.LoggerObject, name)
allLoggers[name] = logger
end
return logger
end
function __module.StashData(env, to)
local ____has = to.__has__
if not ____has then
____has = {}
to.__has__ = ____has
end
to.defaultLogLevel = defaultLogLevel
____has.defaultLogLevel = true
to.customSink = customSink
____has.customSink = true
to.allLoggers = allLoggers
____has.allLoggers = true
end
function __module.RestoreData(env, from)
local ____has = from.__has__
if not ____has then
return
end
if ____has.defaultLogLevel then
defaultLogLevel = from.defaultLogLevel
end
if ____has.customSink then
customSink = from.customSink
end
if ____has.allLoggers then
allLoggers = from.allLoggers
end
end
function __module.UpdateImports()
end
+63
View File
@@ -0,0 +1,63 @@
local ____lualib = require("lualib_bundle")
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local ____exports = __module.env
local M__share_event_event_hub = __MODULE__.Import("share.event.event_hub", __module)
local EventListenerContainer = M__share_event_event_hub.EventListenerContainer
____exports.ScopedObject = __TS__DefineClass("ScopedObject", __module)
local ScopedObject = ____exports.ScopedObject
ScopedObject.name = "ScopedObject"
__TS__ClassExtends(ScopedObject, EventListenerContainer)
function ScopedObject.prototype.____constructor(self, ...)
EventListenerContainer.prototype.____constructor(self, ...)
self.scopedObjects = {}
self.disposed = false
end
function ScopedObject.prototype.IsDisposed(self)
return self.disposed
end
function ScopedObject.prototype.AddScopedObject(self, obj)
if self.disposed then
obj:Dispose()
return
end
self.scopedObjects[obj] = true
end
function ScopedObject.prototype.RemoveScopedObject(self, obj)
self.scopedObjects[obj] = nil
end
function ScopedObject.prototype.GetScopedObjectCount(self)
local count = 0
for _, active in pairs(self.scopedObjects) do
if active == true then
count = count + 1
end
end
return count
end
function ScopedObject.prototype.DisposeAllScopedObjects(self)
local list = {}
for obj, active in pairs(self.scopedObjects) do
if active == true then
list[#list + 1] = obj
end
end
self.scopedObjects = {}
do
local i = 0
while i < #list do
list[i + 1]:Dispose()
i = i + 1
end
end
end
function ScopedObject.prototype.Dispose(self)
if self.disposed then
return
end
self.disposed = true
self:DisposeAllScopedObjects()
EventListenerContainer.prototype.Dispose(self)
end
function __module.UpdateImports()
EventListenerContainer = M__share_event_event_hub.EventListenerContainer
end
+62
View File
@@ -0,0 +1,62 @@
local ____exports = __module.env
---
-- @module_data
local activeHandler = nil
function ____exports.SetupTracebackHandler(handler)
activeHandler = handler
end
local function DefaultDump(msg)
if UnLua ~= nil and UnLua.LogError ~= nil then
UnLua.LogError(msg)
else
print("[ERROR] " .. msg)
end
end
local function OnError(err)
local errText = tostring(err)
local fullStack = debug.traceback(errText, 2)
if activeHandler ~= nil then
if activeHandler.LogTraceback ~= nil then
pcall(activeHandler.LogTraceback, errText, fullStack)
end
if activeHandler.DumpTraceback ~= nil then
pcall(activeHandler.DumpTraceback, fullStack)
else
DefaultDump(fullStack)
end
else
DefaultDump(fullStack)
end
return fullStack
end
--- 带完整堆栈上报的安全调用(对应 gamelogic 的 tbpcall),保留全部多返回值。
function ____exports.tbpcall(fn, ...)
return xpcall(fn, OnError, ...)
end
--- 调用带 self 的对象方法并捕获异常上报堆栈。
function ____exports.tbpcallMethod(fn, selfObj, ...)
return xpcall(fn, OnError, selfObj, ...)
end
function ____exports.ReportError(message)
OnError(message)
end
function __module.StashData(env, to)
local ____has = to.__has__
if not ____has then
____has = {}
to.__has__ = ____has
end
to.activeHandler = activeHandler
____has.activeHandler = true
end
function __module.RestoreData(env, from)
local ____has = from.__has__
if not ____has then
return
end
if ____has.activeHandler then
activeHandler = from.activeHandler
end
end
function __module.UpdateImports()
end