util.events: handler priorities

This commit is contained in:
Waqas Hussain 2009-05-16 15:56:45 +05:00
parent 2a3983a113
commit 9e0d2195f1

View file

@ -2,6 +2,7 @@
local ipairs = ipairs;
local pairs = pairs;
local t_insert = table.insert;
local t_sort = table.sort;
local select = select;
module "events"
@ -19,14 +20,15 @@ function new()
for handler in pairs(_handlers) do
t_insert(index, handler);
end
t_sort(index, function(a, b) return _handlers[a] > _handlers[b]; end);
end
end;
local function add_handler(event, handler)
local function add_handler(event, handler, priority)
local map = event_map[event];
if map then
map[handler] = true;
map[handler] = priority or 0;
else
map = {[handler] = true};
map = {[handler] = priority or 0};
event_map[event] = map;
end
_rebuild_index();