feat: integrate ts2lua-unreal v0.2.1 and UnLua TypeScript (.d.ts) generator

This commit is contained in:
szy73711 committed 2026-11-29 03:08:03 +08:00
1 parent ebce41f347
commit ee2e62bb34
282 files changed
+141794 -261

No files matched your search

+48 -44
View File
@@ -1,93 +1,97 @@
---@class Framework.HotReload
---Coordinates Lua module hot-reloading with UnLua and notifies listeners.
local ____exports = {}
local Log = require("Framework.Log")
local EventBus = require("Framework.EventBus")
local HotReload = {}
HotReload.EVENT_BEFORE_RELOAD = "Framework.BeforeHotReload"
HotReload.EVENT_AFTER_RELOAD = "Framework.AfterHotReload"
____exports.EVENT_BEFORE_RELOAD = "Framework.BeforeHotReload"
____exports.EVENT_AFTER_RELOAD = "Framework.AfterHotReload"
local function GetLuaPackage()
return _G.package
end
local function CollectReloadableGameModules()
local modules = {}
for name, _ in pairs(package.loaded) do
if type(name) == "string" and name:match("^Game%.") then
for name in pairs(GetLuaPackage().loaded) do
if type(name) == "string" and (string.match(name, "^Game%.")) ~= nil then
modules[#modules + 1] = name
end
end
table.sort(modules)
return modules
end
---Reloads a specific Lua module using UnLua's hot-reload sandbox (falls back to package.loaded reset).
---@param moduleName string Dot-separated Lua module name, e.g. "Game.LuaDemoActor"
---@return boolean ok
---@return any resultOrErr
function HotReload.ReloadModule(moduleName)
--- Reloads a specific Lua module using UnLua's hot-reload sandbox (falls back to package.loaded reset).
function ____exports.ReloadModule(moduleName)
if type(moduleName) ~= "string" or moduleName == "" then
return false, "Invalid module name"
end
Log.Info("Hot-reloading Lua module: %s", moduleName)
EventBus.Emit(HotReload.EVENT_BEFORE_RELOAD, moduleName)
EventBus.Emit(____exports.EVENT_BEFORE_RELOAD, moduleName)
local okHr, unluaHr = pcall(require, "UnLua.HotReload")
if okHr and unluaHr and type(unluaHr.reload) == "function" then
local ok, err = pcall(unluaHr.reload, { moduleName })
local hrMod = unluaHr
if okHr and hrMod ~= nil and type(hrMod.reload) == "function" then
local ok, err = pcall(hrMod.reload, {moduleName})
if not ok then
Log.Error("UnLua.HotReload.reload('%s') failed: %s", moduleName, tostring(err))
Log.Error(
"UnLua.HotReload.reload('%s') failed: %s",
moduleName,
tostring(err)
)
return false, err
end
else
package.loaded[moduleName] = nil
GetLuaPackage().loaded[moduleName] = nil
local ok, result = pcall(require, moduleName)
if not ok then
Log.Error("Failed to hot-reload module '%s': %s", moduleName, tostring(result))
Log.Error(
"Failed to hot-reload module '%s': %s",
moduleName,
tostring(result)
)
return false, result
end
end
EventBus.Emit(HotReload.EVENT_AFTER_RELOAD, moduleName)
EventBus.Emit(____exports.EVENT_AFTER_RELOAD, moduleName)
Log.Info("Successfully hot-reloaded Lua module: %s", moduleName)
return true
end
---Triggers UnLua hot-reload across all loaded Game.* modules (supports Saved/HotUpdate/Script overrides).
---@return boolean ok
function HotReload.ReloadAll()
--- Triggers UnLua hot-reload across all loaded Game.* modules (supports Saved/HotUpdate/Script overrides).
function ____exports.ReloadAll()
local gameModules = CollectReloadableGameModules()
Log.Info("Triggering UnLua HotReload (modules=%d)...", #gameModules)
EventBus.Emit(HotReload.EVENT_BEFORE_RELOAD, "*")
EventBus.Emit(____exports.EVENT_BEFORE_RELOAD, "*")
local okHr, unluaHr = pcall(require, "UnLua.HotReload")
if okHr and unluaHr and type(unluaHr.reload) == "function" then
local hrMod = unluaHr
if okHr and hrMod ~= nil and type(hrMod.reload) == "function" then
if #gameModules > 0 then
local ok, err = pcall(unluaHr.reload, gameModules)
local ok, err = pcall(hrMod.reload, gameModules)
if not ok then
Log.Error("UnLua.HotReload.reload(gameModules) failed: %s", tostring(err))
Log.Error(
"UnLua.HotReload.reload(gameModules) failed: %s",
tostring(err)
)
return false
end
end
-- Also run timestamp-based check for any other modified modules
local ok2, err2 = pcall(unluaHr.reload)
local ok2, err2 = pcall(hrMod.reload)
if not ok2 then
Log.Error("UnLua.HotReload.reload() failed: %s", tostring(err2))
Log.Error(
"UnLua.HotReload.reload() failed: %s",
tostring(err2)
)
return false
end
elseif UnLua and type(UnLua.HotReload) == "function" then
elseif UnLua ~= nil and type(UnLua.HotReload) == "function" then
local ok, err = pcall(UnLua.HotReload)
if not ok then
Log.Error("UnLua.HotReload() failed: %s", tostring(err))
Log.Error(
"UnLua.HotReload() failed: %s",
tostring(err)
)
return false
end
else
Log.Warn("UnLua.HotReload is unavailable; skipping global hot reload.")
return false
end
EventBus.Emit(HotReload.EVENT_AFTER_RELOAD, "*")
EventBus.Emit(____exports.EVENT_AFTER_RELOAD, "*")
Log.Info("UnLua HotReload completed.")
return true
end
return HotReload
return ____exports