Enhance dumpTable function to include optional message parameter for improved logging

This commit is contained in:
2025-05-18 11:15:52 +02:00
parent 20a7c0eead
commit eab562b36d

View File

@@ -3,12 +3,14 @@ local _, shared = ...
if not shared.dumpTable then if not shared.dumpTable then
---@param table table ---@param table table
---@param msg string?
---@param depth number? ---@param depth number?
shared.dumpTable = function(table, depth) shared.dumpTable = function(table, msg, depth)
if not table then if not table then
print(tostring(table)) print(tostring(table))
return return
end end
if msg then print(msg) end
if depth == nil then depth = 0 end if depth == nil then depth = 0 end
if depth > 200 then if depth > 200 then
print("Error: Depth > 200 in dumpTable()") print("Error: Depth > 200 in dumpTable()")
@@ -17,7 +19,7 @@ if not shared.dumpTable then
for k, v in pairs(table) do for k, v in pairs(table) do
if type(v) == "table" then if type(v) == "table" then
print(string.rep(" ", depth) .. k .. ":") print(string.rep(" ", depth) .. k .. ":")
shared.dumpTable(v, depth + 1) shared.dumpTable(v, nil, depth + 1)
else else
print(string.rep(" ", depth) .. k .. ": ", v) print(string.rep(" ", depth) .. k .. ": ", v)
end end