66 env.marked["traverse"] = true |
66 env.marked["traverse"] = true |
67 env.marked[traverse] = true |
67 env.marked[traverse] = true |
68 |
68 |
69 -- marks and inserts on the list |
69 -- marks and inserts on the list |
70 edge(env, nil, "_G", "isname", nil) |
70 edge(env, nil, "_G", "isname", nil) |
71 edge(env, nil, _G, "key", "_G") |
71 edge(env, nil, _G, "value", "_G") |
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 |
101 |
101 |
102 local f = env.funcs.table |
102 local f = env.funcs.table |
103 if f then f(obj) end |
103 if f then f(obj) end |
104 |
104 |
105 for key, value in pairs(obj) do |
105 for key, value in pairs(obj) do |
106 edge(env, obj, key, "iskey", nil) |
106 edge(env, obj, key, "key", nil) |
107 edge(env, obj, value, "key", key) |
107 edge(env, obj, value, "value", key) |
108 end |
108 end |
109 |
109 |
110 local mtable = debug.getmetatable(obj) |
110 local mtable = debug.getmetatable(obj) |
111 if mtable then edge(env, obj, mtable, "ismetatable", nil) end |
111 if mtable then edge(env, obj, mtable, "ismetatable", nil) end |
112 |
112 |
171 |
171 |
172 end |
172 end |
173 |
173 |
174 |
174 |
175 -- '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': |
176 -- if 'how' is "iskey", then 'to' is a key and 'value' is nil. |
176 -- if 'how' is "key", then 'to' is a key and 'name' is nil. |
177 -- if 'how' is "key", then 'to' is an object and 'value' is the name of the |
177 -- if 'how' is "value", then 'to' is an object and 'name' is the name of the |
178 -- key. |
178 -- key. |
179 function edge(env, from, to, how, value) |
179 function edge(env, from, to, how, name) |
180 |
180 |
181 local t = type(to) |
181 local t = type(to) |
182 |
182 |
183 if to and (t~="boolean") and (t~="number") and (t~="new") then |
183 if to and (t~="boolean") and (t~="number") and (t~="new") then |
184 -- If the destination object has not been found yet |
184 -- If the destination object has not been found yet |
186 env.marked[to] = true |
186 env.marked[to] = true |
187 List.push(env.list, to) -- puts on the list to be traversed |
187 List.push(env.list, to) -- puts on the list to be traversed |
188 end |
188 end |
189 |
189 |
190 local f = env.funcs.edge |
190 local f = env.funcs.edge |
191 if f then f(from, to, how, value) end |
191 if f then f(from, to, how, name) end |
192 |
192 |
193 end |
193 end |
194 end |
194 end |
195 |
195 |
196 return _M; |
196 return _M; |