Sat, 27 Mar 2010 17:43:08 +0000
Initial commit (importing from old SVN repo which got lost)
0
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | --[[ I created this class for an easy way of managing the objects inside a container in the MOO. ]] |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | containertable = { }; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | function containertable:add(object) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | local subt = self[(object and object._properties.name) or ""]; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | if not subt then subt = { }; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | self[(object and object._properties.name) or ""] = subt; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | -- Also, all object's aliases need to point to subt |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | if object._tags then |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | for i, tag in ipairs(object._tags) do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | self[tag] = subt; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | table.insert(subt, object); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | return object; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | function containertable:remove(object) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | local subt = self[(object._properties and object._properties.name) or ""]; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | if not subt then return false; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | for n, stored_object in pairs(subt) do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | if object == stored_object then table.remove(subt, n); return object; end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | return false; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | function containertable:addalias(name, tag) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | self[tag] = self[name]; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | function containertable:findobject(name) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | local subt = self[name or ""]; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | if not subt then subt = self[""]; if not subt then return; end end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | return subt[1]; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | function containertable:getallobjects() |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | all = {}; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | for tag, list in pairs(self) do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | for n, object in ipairs(list) do |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | all[object] = true; |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | return all; -- We return a table, where the objects are the keys, and the values are true |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | end |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | function createcontainertable(t) |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | return setmetatable(t or {}, { __index = containertable }); |
cc66ad6b0d75
Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | end |