72 |
72 |
73 -- traverses the active thread |
73 -- traverses the active thread |
74 -- inserts the local variables |
74 -- inserts the local variables |
75 -- interates over the function on the stack, starting from the one that |
75 -- interates over the function on the stack, starting from the one that |
76 -- called traverse |
76 -- called traverse |
|
77 |
77 for i=2, math.huge do |
78 for i=2, math.huge do |
78 local info = debug.getinfo(i, "f") |
79 local info = debug.getinfo(i, "f") |
79 if not info then break end |
80 if not info then break end |
80 for j=1, math.huge do |
81 for j=1, math.huge do |
81 local n, v = debug.getlocal(i, j) |
82 local n, v = debug.getlocal(i, j) |
84 edge(env, nil, n, "isname", nil) |
85 edge(env, nil, n, "isname", nil) |
85 edge(env, nil, v, "local", n) |
86 edge(env, nil, v, "local", n) |
86 end |
87 end |
87 end |
88 end |
88 |
89 |
89 while not List.isempty(env.list) do |
90 while not List.isempty(env.list) do |
90 |
91 |
91 local obj = List.pop(env.list) |
92 local obj = List.pop(env.list) |
92 local t = type(obj) |
93 local t = type(obj) |
93 traverse["traverse" .. t](env, obj) |
94 traverse["traverse" .. t](env, obj) |
94 |
95 |
95 end |
96 end |
101 local f = env.funcs.table |
102 local f = env.funcs.table |
102 if f then f(obj) end |
103 if f then f(obj) end |
103 |
104 |
104 for key, value in pairs(obj) do |
105 for key, value in pairs(obj) do |
105 edge(env, obj, key, "iskey", nil) |
106 edge(env, obj, key, "iskey", nil) |
106 edge(env, obj, value, "key", key) |
107 edge(env, obj, value, "key", key) |
107 end |
108 end |
108 |
109 |
109 local mtable = debug.getmetatable(obj) |
110 local mtable = debug.getmetatable(obj) |
110 if mtable then edge(env, obj, mtable, "ismetatable", nil) end |
111 if mtable then edge(env, obj, mtable, "ismetatable", nil) end |
111 |
112 |
170 |
171 |
171 end |
172 end |
172 |
173 |
173 |
174 |
174 -- 'how' is a string that identifies the content of 'to' and 'value': |
175 -- 'how' is a string that identifies the content of 'to' and 'value': |
175 -- if 'how' is "iskey", then 'to' é is a key and 'value' is nil. |
176 -- if 'how' is "iskey", then 'to' é is a key and 'value' is nil. |
176 -- if 'how' is "key", then 'to' is an object and 'value' is the name of the |
177 -- if 'how' is "key", then 'to' is an object and 'value' is the name of the |
177 -- key. |
178 -- key. |
178 function edge(env, from, to, how, value) |
179 function edge(env, from, to, how, value) |
179 |
180 |
180 local t = type(to) |
181 local t = type(to) |