Annotate

core/eventmanager.lua @ 2684:837e697562ad

Merge with 0.7
author Matthew Wild <mwild1@gmail.com>
date Sat, 20 Feb 2010 00:53:04 +0000
parent 1522:569d58d21612
child 2923:b7049746bd29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
1 -- Prosody IM
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
4 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 1514
diff changeset
8
1514
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
9
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
10 local t_insert = table.insert;
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
11 local ipairs = ipairs;
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
12
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
13 module "eventmanager"
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
14
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
15 local event_handlers = {};
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
16
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
17 function add_event_hook(name, handler)
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
18 if not event_handlers[name] then
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
19 event_handlers[name] = {};
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
20 end
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
21 t_insert(event_handlers[name] , handler);
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
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
24 function fire_event(name, ...)
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
25 local event_handlers = event_handlers[name];
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
26 if event_handlers then
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
27 for name, handler in ipairs(event_handlers) do
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
28 handler(...);
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
29 end
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
30 end
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
31 end
0c706c3d2e30 eventmanager: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents: 569
diff changeset
32
569
5216efe6088b Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 return _M;