aboutsummaryrefslogtreecommitdiffstats
path: root/util/events.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-05-16 15:56:45 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-05-16 15:56:45 +0500
commit9e0d2195f12aedb7d9767c901bde482ada9b0945 (patch)
treef87c6b1921b06fa795c806e2447d5b435b67e440 /util/events.lua
parent2a3983a113648bc7217c6b1ef1a95deea2b9c6fa (diff)
downloadprosody-9e0d2195f12aedb7d9767c901bde482ada9b0945.tar.gz
prosody-9e0d2195f12aedb7d9767c901bde482ada9b0945.zip
util.events: handler priorities
Diffstat (limited to 'util/events.lua')
-rw-r--r--util/events.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/util/events.lua b/util/events.lua
index 704d31a4..54816271 100644
--- a/util/events.lua
+++ b/util/events.lua
@@ -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();