Rename dumpTable to dump and make it work with any values
This commit is contained in:
@@ -1,25 +1,29 @@
|
||||
local _, shared = ...
|
||||
---@cast shared HeimdallShared
|
||||
|
||||
if not shared.dumpTable then
|
||||
---@param table table
|
||||
if not shared.dump then
|
||||
---@param value any
|
||||
---@param msg string?
|
||||
---@param depth number?
|
||||
shared.dumpTable = function(table, msg, depth)
|
||||
if not table then
|
||||
print(tostring(table))
|
||||
shared.dump = function(value, msg, depth)
|
||||
if not value then
|
||||
print(tostring(value))
|
||||
return
|
||||
end
|
||||
if type(value) ~= "table" then
|
||||
print(tostring(value))
|
||||
return
|
||||
end
|
||||
if msg then print(msg) end
|
||||
if depth == nil then depth = 0 end
|
||||
if depth > 200 then
|
||||
print("Error: Depth > 200 in dumpTable()")
|
||||
print("Error: Depth > 200 in dump()")
|
||||
return
|
||||
end
|
||||
for k, v in pairs(table) do
|
||||
for k, v in pairs(value) do
|
||||
if type(v) == "table" then
|
||||
print(string.rep(" ", depth) .. tostring(k) .. ":")
|
||||
shared.dumpTable(v, nil, depth + 1)
|
||||
shared.dump(v, msg, depth + 1)
|
||||
else
|
||||
print(string.rep(" ", depth) .. tostring(k) .. ": " .. tostring(v))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user