Software /
code /
prosody
Annotate
core/eventmanager.lua @ 1239:335d9a612477
prosody: Remove global functions
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 30 May 2009 14:07:14 +0100 |
parent | 569:5216efe6088b |
child | 1514:0c706c3d2e30 |
rev | line source |
---|---|
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; |