feat: add L_LuaDemo scene and verify UnLua Tick, input, and hot-reload
This commit is contained in:
1 parent
943af16954
commit
256a60ac80
13 files changed
+670
-18
No files matched your search
@@ -8,8 +8,19 @@ local HotReload = {}
|
||||
HotReload.EVENT_BEFORE_RELOAD = "Framework.BeforeHotReload"
|
||||
HotReload.EVENT_AFTER_RELOAD = "Framework.AfterHotReload"
|
||||
|
||||
---Reloads a specific Lua module (clears package.loaded and re-requires it).
|
||||
---@param moduleName string Dot-separated Lua module name, e.g. "Game.LuaGameMode"
|
||||
local function CollectReloadableGameModules()
|
||||
local modules = {}
|
||||
for name, _ in pairs(package.loaded) do
|
||||
if type(name) == "string" and name:match("^Game%.") 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)
|
||||
@@ -20,25 +31,50 @@ function HotReload.ReloadModule(moduleName)
|
||||
Log.Info("Hot-reloading Lua module: %s", moduleName)
|
||||
EventBus.Emit(HotReload.EVENT_BEFORE_RELOAD, moduleName)
|
||||
|
||||
package.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))
|
||||
return false, result
|
||||
local okHr, unluaHr = pcall(require, "UnLua.HotReload")
|
||||
if okHr and unluaHr and type(unluaHr.reload) == "function" then
|
||||
local ok, err = pcall(unluaHr.reload, { moduleName })
|
||||
if not ok then
|
||||
Log.Error("UnLua.HotReload.reload('%s') failed: %s", moduleName, tostring(err))
|
||||
return false, err
|
||||
end
|
||||
else
|
||||
package.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))
|
||||
return false, result
|
||||
end
|
||||
end
|
||||
|
||||
EventBus.Emit(HotReload.EVENT_AFTER_RELOAD, moduleName, result)
|
||||
EventBus.Emit(HotReload.EVENT_AFTER_RELOAD, moduleName)
|
||||
Log.Info("Successfully hot-reloaded Lua module: %s", moduleName)
|
||||
return true, result
|
||||
return true
|
||||
end
|
||||
|
||||
---Triggers UnLua's built-in hot reload across all loaded modules.
|
||||
---Triggers UnLua hot-reload across all loaded Game.* modules (supports Saved/HotUpdate/Script overrides).
|
||||
---@return boolean ok
|
||||
function HotReload.ReloadAll()
|
||||
Log.Info("Triggering full UnLua HotReload...")
|
||||
local gameModules = CollectReloadableGameModules()
|
||||
Log.Info("Triggering UnLua HotReload (modules=%d)...", #gameModules)
|
||||
EventBus.Emit(HotReload.EVENT_BEFORE_RELOAD, "*")
|
||||
|
||||
if UnLua and type(UnLua.HotReload) == "function" then
|
||||
local okHr, unluaHr = pcall(require, "UnLua.HotReload")
|
||||
if okHr and unluaHr and type(unluaHr.reload) == "function" then
|
||||
if #gameModules > 0 then
|
||||
local ok, err = pcall(unluaHr.reload, gameModules)
|
||||
if not ok then
|
||||
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)
|
||||
if not ok2 then
|
||||
Log.Error("UnLua.HotReload.reload() failed: %s", tostring(err2))
|
||||
return false
|
||||
end
|
||||
elseif UnLua and type(UnLua.HotReload) == "function" then
|
||||
local ok, err = pcall(UnLua.HotReload)
|
||||
if not ok then
|
||||
Log.Error("UnLua.HotReload() failed: %s", tostring(err))
|
||||
|
||||
Reference in new issue
Block a user