Skip to content

Commit e6aa68c

Browse files
committed
debugDescriptionString: fix infinite recursion avoidance, add documentation
1 parent 31f3855 commit e6aa68c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

MasterFramework 42/Framework/debug.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ function Error(...)
4242
Spring_Echo(errorString)
4343
end
4444

45+
--[[
46+
Generates a string detailing the contents of a table - recursively. Calling this,
47+
48+
Parameters:
49+
- `table`: the table whose contents are to be displayed
50+
- `name`: an optional string describing the table provided - e.g. the key used to access this table from its parent table
51+
- `indentation`: an optional integer indicating how nested this table is. Usually, you will provide `0` or `nil`; this is primarily for the sake of recursion.
52+
- `describedTables`: a table keyed by tables whose descriptions have been generated. This table is used to avoid infinite recursion in the case of recursive table references.
53+
54+
Note: Call this as framework.debugDescription, NOT framework:debugDescription!
55+
]]
4556
function debugDescriptionString(table, name, indentation, describedTables)
4657
describedTables = describedTables or {}
4758
local description = ""
@@ -53,7 +64,7 @@ function debugDescriptionString(table, name, indentation, describedTables)
5364
describedTables[table] = true
5465
for key, value in pairs(table) do
5566
if type(value) == "table" then
56-
description = description .. "\n" .. debugDescriptionString(value, key, indentation + 1)
67+
description = description .. "\n" .. debugDescriptionString(value, key, indentation + 1, describedTables)
5768
else
5869
description = description .. "\n\255\100\100\100" .. string.rep("| ", indentation + 1) .. "\255\255\255\255" .. tostring(key) .. "\255\100\100\100:\255\255\255\255 " .. tostring(value)
5970
end

0 commit comments

Comments
 (0)