# HG changeset patch # User Matthew Wild # Date 1430227123 -3600 # Node ID 859e9af53aa1513c8e0eeadf14bdbb85305833ae # Parent 3003d041c15909d31b1c5e9b9964e3e06bd26500 moduleapi: New methods for modules to conveniently wrap events diff -r 3003d041c159 -r 859e9af53aa1 core/moduleapi.lua --- a/core/moduleapi.lua Tue Apr 28 13:52:07 2015 +0100 +++ b/core/moduleapi.lua Tue Apr 28 14:18:43 2015 +0100 @@ -120,6 +120,18 @@ return self:unhook_object_event((hosts[self.host] or prosody).events, event, handler); end +function api:wrap_object_event(events_object, event, handler) + return self:hook_object_event(assert(events_object.wrappers, "no wrappers"), event, handler); +end + +function api:wrap_event(event, handler) + return self:wrap_object_event((hosts[self.host] or prosody).events, event, handler); +end + +function api:wrap_global(event, handler) + return self:hook_object_event(prosody.events, event, handler, priority); +end + function api:require(lib) local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); if not f then