Software /
code /
prosody
Annotate
core/eventmanager.lua @ 1514:0c706c3d2e30
eventmanager: Convert from Windows line endings
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 10 Jul 2009 02:11:00 +0100 |
parent | 569:5216efe6088b |
child | 1522:569d58d21612 |
rev | line source |
---|---|
1514
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
1 |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
2 local t_insert = table.insert; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
3 local ipairs = ipairs; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
4 |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
5 module "eventmanager" |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
6 |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
7 local event_handlers = {}; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
8 |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
9 function add_event_hook(name, handler) |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
10 if not event_handlers[name] then |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
11 event_handlers[name] = {}; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
12 end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
13 t_insert(event_handlers[name] , handler); |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
14 end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
15 |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
16 function fire_event(name, ...) |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
17 local event_handlers = event_handlers[name]; |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
18 if event_handlers then |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
19 for name, handler in ipairs(event_handlers) do |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
20 handler(...); |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
21 end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
22 end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
23 end |
0c706c3d2e30
eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
24 |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 return _M; |