1 local m
= require
"graph"
3 local vbox
, hbox
= m
.vbox
, m
.hbox
5 -- Get rid of ':' in table representation - only for invisible strings
6 local function tname(t
)
7 local s
= string.gsub(tostring(t
), ": ", "")
12 local function tport(s
)
13 return "<"..tname(s
)..">"
16 -- Return a closure that creates a node from a table
17 local function tnode(g
, t
, cache
)
20 for k
,v
in pairs(t
) do
21 if type(v
) == "table" then
22 if t
~= v
and v
~= _G
and v
~= _G
.graph
then
23 if cache
[v
] == nil then
25 table.insert(fields
, vbox
{tostring(k
), tport(k
)..tostring(v
)})
28 g
:edge(tname(t
)..":"..tname(k
), tname(v
))
31 table.insert(fields
, vbox
{tostring(k
), tport(k
)..tostring(v
)})
34 g
:record
{tname(t
), hbox
{tostring(t
), unpack(fields
)}}
37 -- Retrun a graph representing a nested table structure
38 local function tgraph(t
)
39 local g
= m
.open("GG")
45 ------------------------------------------
47 ------------------------------------------
57 aField
= "This is a field",
58 anotherField
= "This is another field",
60 subfield
= "subfield",
61 [1] = "index aTable[1]",
83 t
[i
][j
] = "field["..i
.."]["..j
.."]"
91 print("Select table to show:")
92 print("(1) example table")
93 print("(2) double indexed array")
94 print("(3) snmp module")
95 print("(4) socket module")
96 print("(5) binary tree")
98 io
.write("select: ") io
.flush()
104 et
[3] = require
"snmp"
107 et
[4] = require
"socket"
111 local foo
= assert(loadfile("tree.lua"))
114 local ix
= tonumber(s
)
115 if et
[ix
] ~= nil then
116 local g
= tgraph(et
[tonumber(s
)])
117 print("Close the display window completely to continue.")
119 g
:render("png", "out.png", "dot")
122 print("Selected item is NIL - cannot produce graph")