File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -11,8 +11,15 @@ function dump(o)
1111end
1212
1313-- improved formatting for dumping tables
14- function tdump (tbl , indent )
14+ function tdump (tbl , indent , refs )
15+ if not refs then refs = {} end
1516 if not indent then indent = 0 end
17+ local address = string.format (" %p" , tbl )
18+ if refs [address ] ~= nil then
19+ print (string.rep (" " , indent ) .. " (circular reference to " .. address .. " )" )
20+ return
21+ end
22+
1623 if tbl .t then
1724 print (string.rep (" " , indent ) .. tbl .t )
1825 end
@@ -22,7 +29,8 @@ function tdump (tbl, indent)
2229 formatting = string.rep (" " , indent ) .. k .. " : "
2330 if type (v ) == " table" then
2431 print (formatting )
25- tdump (v , indent + 1 )
32+ refs [address ] = true
33+ tdump (v , indent + 1 , refs )
2634 elseif type (v ) == ' boolean' then
2735 print (formatting .. tostring (v ))
2836 elseif (v ~= nil ) then
Original file line number Diff line number Diff line change 11-- debug.lua
22-- Copyright (C) 2020 by RStudio, PBC
33-- improved formatting for dumping tables
4- function tdump (tbl , indent )
4+ function tdump (tbl , indent , refs )
5+ if not refs then refs = {} end
56 if not indent then indent = 0 end
7+ local address = string.format (" %p" , tbl )
8+ if refs [address ] ~= nil then
9+ print (string.rep (" " , indent ) .. " (circular reference to " .. address .. " )" )
10+ return
11+ end
12+
613 if tbl .t then
714 print (string.rep (" " , indent ) .. tbl .t )
815 end
@@ -11,8 +18,9 @@ function tdump (tbl, indent)
1118 empty = false
1219 formatting = string.rep (" " , indent ) .. k .. " : "
1320 if type (v ) == " table" then
14- print (formatting )
15- tdump (v , indent + 1 )
21+ print (formatting .. " table: " .. address )
22+ refs [address ] = true
23+ tdump (v , indent + 1 , refs )
1624 elseif type (v ) == ' boolean' then
1725 print (formatting .. tostring (v ))
1826 elseif (v ~= nil ) then
You can’t perform that action at this time.
0 commit comments