forked from Tencent/UnLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG6HotfixHelper.lua
More file actions
99 lines (84 loc) · 2.86 KB
/
G6HotfixHelper.lua
File metadata and controls
99 lines (84 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
------------------------------------------
--- G6HotFix 的加载,用于加载整个Lua系统
------------------------------------------
--
-- G6采用Require来加载Lua文件,以提供HotFix支持,
-- 所以在加载其他Lua文件之前,要先将HotFix加载
--
-- Load HotFix
print("Load HotFix...");
local hotfix_func,err = UELoadLuaFile("G6Hotfix.lua");
if (hotfix_func) and type(hotfix_func) == "function" then
package.loaded["g6hotfix"] = hotfix_func();
_G.G6HotFix = package.loaded["g6hotfix"];
else
print("Require HotFix Fail " .. tostring(err));
end
-- _G.G6HotFix = require "G6Core.Misc.G6Hotfix"
print("Load HotFix --->");
--
-- 所有之后的Lua文件使用的是hotfix的require了
--
--- 重新加载某个文件
---@param filepath string
function ReloadFile(filepath)
if nil == filepath then
return
end
_G.G6HotFix.ReloadFile(filepath)
end
--- 重新加载所有文件
function ReloadAll()
_G.G6HotFix.ClearLoadedModule()
end
--- 打印表内容
---@overload fun(tbl: table):string
---@param TableToPrint table
---@param MaxIntent number
---@return string
function _G.TableToString (TableToPrint, MaxIntent)
local HandlerdTable = {}
local function ItretePrintTable(TP, Indent)
if not Indent then Indent = 0 end
if type(TP) ~= "table" then return tostring(TP) end
if(Indent > MaxIntent) then return tostring(TP) end
if HandlerdTable[TP] then
return "";
end
HandlerdTable[TP] = true
local StrToPrint = string.rep(" ", Indent) .. "{\r\n"
Indent = Indent + 2
for k, v in pairs(TP) do
StrToPrint = StrToPrint .. string.rep(" ", Indent)
if (type(k) == "number") then
StrToPrint = StrToPrint .. "[" .. k .. "] = "
elseif (type(k) == "string") then
StrToPrint = StrToPrint .. k .. "= "
else
StrToPrint = StrToPrint .. tostring(k) .. " = "
end
if (type(v) == "number") then
StrToPrint = StrToPrint .. v .. ",\r\n"
elseif (type(v) == "string") then
StrToPrint = StrToPrint .. "\"" .. v .. "\",\r\n"
elseif (type(v) == "table") then
StrToPrint = StrToPrint .. tostring(v) .. ItretePrintTable(v, Indent + 2) .. ",\r\n"
else
StrToPrint = StrToPrint .. "\"" .. tostring(v) .. "\",\r\n"
end
end
StrToPrint = StrToPrint .. string.rep(" ", Indent-2) .. "}"
return StrToPrint
end
if MaxIntent == nil then
MaxIntent = 64
end
return ItretePrintTable(TableToPrint)
end
--- hotfix所有修改的文件
--- @param bNotPrintHotfixFile boolean @是否需要打印日志
function HotFix(bNotPrintHotfixFile)
_G.G6HotFix.HotFixModifyFile(bNotPrintHotfixFile)
end
ReloadAll()
print("PRINT G6ENV : ", TableToString(G6ENV) )