So I wrote this function to print the contents of a table for debugging purposes. I've tested it in cases that I have generated, but I keep getting stack overflow errors when using it on certain tables (these being ones made by the Roblox Animation Editor, so I don't exactly know their contents hence the function) .
My question is: What could I throw at this to create a stack overflow? I get that excessive recursion could cause this, but I'm not exactly sure how I could achieve that by just traversing tables. I don't believe they're excessively large or anything, but maybe I under estimate what it takes to cause a stack overflow with this.
function DisplayTable(tab, depth) --returns a string representation of a table and it's contents.
depth = depth and depth + 1 or 1
local str = ""
for i,v in pairs(tab) do
str = str..string.rep("\t", depth)..tostring(v).."\n"
if type(v) == "table" then
str = str..DisplayTable(v, depth).."\n"
end
end
if depth == 1 then
return tostring(tab).."\n"..str --tack the original table at start.
end
return str
end
What the output looks like given a fairly normal table:
local t = {
a = "test",
1,
{5,2,5},
{"b",{1,2,3}},
{"goback",5,4,3}
}
>
table: 210EC6E0
1
table: 210EB9C0
5
2
5
table: 210EBC90
b
table: 210EC650
1
2
3
table: 210EB150
goback
5
4
3
test

1 comment
ah, thanks! I didn't think about circular references like that, for some reason they factored into the problem in my head as just a reference to the table and not it's contents. I'm sure that was the problem.