Wed, 18 Feb 2009 19:34:26 +0000
Automated merge with http://waqas.ath.cx:8000/
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | local t_insert = table.insert; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local ipairs = ipairs; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | module "eventmanager" |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | local event_handlers = {}; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | function add_event_hook(name, handler) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | if not event_handlers[name] then |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | event_handlers[name] = {}; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | t_insert(event_handlers[name] , handler); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | function fire_event(name, ...) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | local event_handlers = event_handlers[name]; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | if event_handlers then |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | for name, handler in ipairs(event_handlers) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | handler(...); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | return _M; |