luatraverse.lua

Mon, 26 Oct 2009 02:41:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 26 Oct 2009 02:41:08 +0000
changeset 7
258aedad056c
parent 6
ab49e2e3d709
child 8
b75900150167
permissions
-rw-r--r--

Clear up the confusing key/value/name issue

1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
1 -------------------------------------------------------------------------------
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
2 -- This module implements a function that traverses all live objects.
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
3 -- You can implement your own function to pass as a parameter of traverse
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
4 -- and give you the information you want. As an example we have implemented
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
5 -- countreferences and findallpaths
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
6 --
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
7 -- Alexandra Barros - 2006.03.15
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
8 -------------------------------------------------------------------------------
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
9
3
842f3003db2a Rename module 'gc' -> 'traverse'
Matthew Wild <mwild1@gmail.com>
parents: 2
diff changeset
10 module("traverse", package.seeall)
842f3003db2a Rename module 'gc' -> 'traverse'
Matthew Wild <mwild1@gmail.com>
parents: 2
diff changeset
11 local traverse = _M;
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
12
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
13 local List = {}
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
14
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
15 function List.new ()
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
16 return {first = 0, last = -1}
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
17 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
18
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
19 function List.push (list, value)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
20 local last = list.last + 1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
21 list.last = last
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
22 list[last] = value
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
23 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
24
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
25 function List.pop (list)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
26 local first = list.first
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
27 if first > list.last then error("list is empty") end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
28 local value = list[first]
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
29 list[first] = nil
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
30 list.first = first + 1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
31 return value
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
32 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
33
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
34 function List.isempty (list)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
35 return list.first > list.last
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
36 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
37
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
38 -- Counts all references for a given object
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
39 function countreferences(value)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
40 local count = -1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
41 local f = function(from, to, how, v)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
42 if to == value then
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
43 count = count + 1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
44 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
45 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
46 traverse({edge=f}, {count, f})
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
47 return count
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
48 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
49
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
50 -- Main function
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
51 -- 'funcs' is a table that contains a funcation for every lua type and also the
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
52 -- function edge edge (traverseedge).
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
53 function traverse(funcs, ignoreobjs)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
54
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
55 -- The keys of the marked table are the objetcts (for example, table: 00442330).
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
56 -- The value of each key is true if the object has been found and false
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
57 -- otherwise.
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
58 local env = {marked = {}, list=List.new(), funcs=funcs}
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
59
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
60 if ignoreobjs then
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
61 for i=1, #ignoreobjs do
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
62 env.marked[ignoreobjs[i]] = true
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
63 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
64 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
65
3
842f3003db2a Rename module 'gc' -> 'traverse'
Matthew Wild <mwild1@gmail.com>
parents: 2
diff changeset
66 env.marked["traverse"] = true
842f3003db2a Rename module 'gc' -> 'traverse'
Matthew Wild <mwild1@gmail.com>
parents: 2
diff changeset
67 env.marked[traverse] = true
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
68
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
69 -- marks and inserts on the list
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
70 edge(env, nil, "_G", "isname", nil)
7
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
71 edge(env, nil, _G, "value", "_G")
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
72
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
73 -- traverses the active thread
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
74 -- inserts the local variables
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
75 -- interates over the function on the stack, starting from the one that
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
76 -- called traverse
4
a4f608729bbf Whitespace and various fixes, return _M
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
77
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
78 for i=2, math.huge do
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
79 local info = debug.getinfo(i, "f")
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
80 if not info then break end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
81 for j=1, math.huge do
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
82 local n, v = debug.getlocal(i, j)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
83 if not n then break end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
84
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
85 edge(env, nil, n, "isname", nil)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
86 edge(env, nil, v, "local", n)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
87 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
88 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
89
4
a4f608729bbf Whitespace and various fixes, return _M
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
90 while not List.isempty(env.list) do
a4f608729bbf Whitespace and various fixes, return _M
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
91
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
92 local obj = List.pop(env.list)
3
842f3003db2a Rename module 'gc' -> 'traverse'
Matthew Wild <mwild1@gmail.com>
parents: 2
diff changeset
93 local t = type(obj)
842f3003db2a Rename module 'gc' -> 'traverse'
Matthew Wild <mwild1@gmail.com>
parents: 2
diff changeset
94 traverse["traverse" .. t](env, obj)
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
95
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
96 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
97
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
98 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
99
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
100 function traversetable(env, obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
101
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
102 local f = env.funcs.table
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
103 if f then f(obj) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
104
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
105 for key, value in pairs(obj) do
7
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
106 edge(env, obj, key, "key", nil)
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
107 edge(env, obj, value, "value", key)
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
108 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
109
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
110 local mtable = debug.getmetatable(obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
111 if mtable then edge(env, obj, mtable, "ismetatable", nil) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
112
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
113 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
114
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
115 function traversestring(env, obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
116 local f = env.funcs.string
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
117 if f then f(obj) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
118
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
119 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
120
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
121 function traverseuserdata(env, obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
122 local f = env.funcs.userdata
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
123 if f then f(obj) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
124
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
125 local mtable = debug.getmetatable(obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
126 if mtable then edge(env, obj, mtable, "ismetatable", nil) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
127
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
128 local fenv = debug.getfenv(obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
129 if fenv then edge(env, obj, fenv, "environment", nil) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
130
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
131 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
132
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
133 function traversefunction(env, obj)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
134 local f = env.funcs.func
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
135 if f then f(obj) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
136
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
137 -- gets the upvalues
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
138 local i = 1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
139 while true do
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
140 local n, v = debug.getupvalue(obj, i)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
141 if not n then break end -- when there is no upvalues
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
142 edge(env, obj, n, "isname", nil)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
143 edge(env, obj, v, "upvalue", n)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
144 i = i + 1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
145 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
146
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
147 local fenv = debug.getfenv(obj)
5
b6d77a6cf45b enviroment -> environment
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
148 edge(env, obj, fenv, "environment", nil)
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
149
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
150 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
151
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
152 function traversethread(env, t)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
153 local f = env.funcs.thread
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
154 if f then f(t) end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
155
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
156 for i=1, math.huge do
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
157 local info = debug.getinfo(t, i, "f")
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
158 if not info then break end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
159 for j=1, math.huge do
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
160 local n, v = debug.getlocal(t, i , j)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
161 if not n then break end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
162 print(n, v)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
163
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
164 edge(env, nil, n, "isname", nil)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
165 edge(env, nil, v, "local", n)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
166 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
167 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
168
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
169 local fenv = debug.getfenv(t)
5
b6d77a6cf45b enviroment -> environment
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
170 edge(env, t, fenv, "environment", nil)
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
171
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
172 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
173
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
174
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
175 -- 'how' is a string that identifies the content of 'to' and 'value':
7
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
176 -- if 'how' is "key", then 'to' is a key and 'name' is nil.
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
177 -- if 'how' is "value", then 'to' is an object and 'name' is the name of the
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
178 -- key.
7
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
179 function edge(env, from, to, how, name)
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
180
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
181 local t = type(to)
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
182
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
183 if to and (t~="boolean") and (t~="number") and (t~="new") then
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
184 -- If the destination object has not been found yet
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
185 if not env.marked[to] then
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
186 env.marked[to] = true
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
187 List.push(env.list, to) -- puts on the list to be traversed
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
188 end
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
189
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
190 local f = env.funcs.edge
7
258aedad056c Clear up the confusing key/value/name issue
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
191 if f then f(from, to, how, name) end
1
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
192
036168493972 Converting to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
193 end
4
a4f608729bbf Whitespace and various fixes, return _M
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
194 end
a4f608729bbf Whitespace and various fixes, return _M
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
195
a4f608729bbf Whitespace and various fixes, return _M
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
196 return _M;

mercurial