# HG changeset patch # User John@Yosemite-PC # Date 1332804027 14400 # Node ID 619e4b9c3cd98aecfaf0bc510df3d32c1ac9c7bf # Parent 9b1588bd43983922321f1273e1078a7f6974cb9e Stop recursion loops diff -r 9b1588bd4398 -r 619e4b9c3cd9 Utility.lua --- a/Utility.lua Mon Mar 26 09:51:57 2012 -0400 +++ b/Utility.lua Mon Mar 26 19:20:27 2012 -0400 @@ -2,6 +2,7 @@ local pairs=pairs local tostring=tostring local type=type +local table=table local getmetatable=getmetatable local setmetatable=setmetatable @@ -37,11 +38,12 @@ return setmetatable(u, getmetatable(t)) end -function PrintTable(table, depth) +function PrintTable(tabl, depth, history) depth = depth or "" - if not table then return end + history = history or {} + if not tabl then return end if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end - for i,v in pairs(table) do + for i,v in pairs(tabl) do if( type(v) == "string" ) then print(depth .. i .. " - " .. v) elseif( type(v) == "number" ) then @@ -49,7 +51,17 @@ elseif( type(v) == "table" ) then --if v == table then return end print(depth .. tostring(i) .." - ") - PrintTable(v,depth.." ") + if history then + for i,vh in pairs(history) do + if vh==tabl then + print(depth.. " - circular reference detected; halting print") + return + end + end + end + table.insert(history,tabl) + PrintTable(v,depth.." ",history) + table.remove(history) elseif( type(v) == "boolean" ) then print(depth .. i .. " - " .. tostring(v)) elseif( type(v) == "function" ) then