Annotate

core/eventmanager.lua @ 1478:da11f2652ae9

sessionmanager: Replace raw session by an event data table for resource bind/unbind events, allowing extra data
author Waqas Hussain <waqas20@gmail.com>
date Sun, 05 Jul 2009 16:21:58 +0500
parent 569:5216efe6088b
child 1514:0c706c3d2e30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;