Comparison

core/eventmanager.lua @ 569:5216efe6088b

Add hostmanager, and eventmanager
author Matthew Wild <mwild1@gmail.com>
date Sat, 06 Dec 2008 03:41:49 +0000
child 1514:0c706c3d2e30
comparison
equal deleted inserted replaced
568:b2464849c1b0 569:5216efe6088b
1
2 local t_insert = table.insert;
3 local ipairs = ipairs;
4
5 module "eventmanager"
6
7 local event_handlers = {};
8
9 function add_event_hook(name, handler)
10 if not event_handlers[name] then
11 event_handlers[name] = {};
12 end
13 t_insert(event_handlers[name] , handler);
14 end
15
16 function fire_event(name, ...)
17 local event_handlers = event_handlers[name];
18 if event_handlers then
19 for name, handler in ipairs(event_handlers) do
20 handler(...);
21 end
22 end
23 end
24
25 return _M;