-- 创建文件保存路径
local filePath = "Facade_table_unique_dump.txt"
-- 使用弱表记录已处理过的表引用
local seenTables = {}
setmetatable(seenTables, {__mode = "v"})
-- 优化后的递归函数
local function dumpTable(t, file, depth, maxDepth, path)
if depth > maxDepth or seenTables[t] then
return
end
seenTables[t] = true
file:write(string.rep(" ", depth-1)..path.." = {\n")
local sortedKeys = {}
for k in pairs(t) do
table.insert(sortedKeys, k)
end
table.sort(sortedKeys, function(a, b)
return tostring(a) < tostring(b)
end)
for _, k in ipairs(sortedKeys) do
local v = t[k]
local newPath = path.."."..tostring(k)
local line = string.rep(" ", depth)..tostring(k).." = "
if type(v) == "table" then
file:write(line.."{\n")
dumpTable(v, file, depth+1, maxDepth, newPath)
file:write(string.rep(" ", depth).."}\n")
else
file:write(line..tostring(v).."\n")
end
end
file:write(string.rep(" ", depth-1).."}\n")
end
-- 主执行逻辑
local file = io.open(filePath, "w")
if file then
file:write("-- global.Facade 精简表结构 --\n")
dumpTable(global.Facade, file, 1, 5, "Facade")
file:close()
SL:print("去重后的Facade表已保存到:"..filePath)
else
SL:print("文件创建失败:"..filePath)
end