diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-08-18 12:30:06 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-08-18 12:30:06 +0500 |
commit | 3900d20a7cacdfc3c9c72e0da7836954ef6a3511 (patch) | |
tree | 798c4738a61baa8c4d021b98ff41ac9490d4ff4c /core | |
parent | dc32d11948edcf57bc8616f54ec558e0aa0e6763 (diff) | |
download | prosody-3900d20a7cacdfc3c9c72e0da7836954ef6a3511.tar.gz prosody-3900d20a7cacdfc3c9c72e0da7836954ef6a3511.zip |
Added: functions add_item and remove_item to add and remove items to the module API
Diffstat (limited to 'core')
-rw-r--r-- | core/modulemanager.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua index c2e6e68e..bc779d76 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -422,6 +422,25 @@ function api:get_option(name, default_value) return config.get(self.host, self.name, name) or config.get(self.host, "core", name) or default_value; end +local t_remove = _G.table.remove; +local module_items = multitable_new(); +function api:add_item(key, value) + self.items = self.items or {}; + self.items[key] = self.items[key] or {}; + t_insert(self.items[key], value); + self:fire_event("item-added/"..key, {source = self, item = value}); +end +function api:remove_item(key, value) + local t = self.items and self.items[key] or NULL; + for i = #t,1,-1 do + if t[i] == value then + t_remove(self.items[key], i); + self:fire_event("item-removed/"..key, {source = self, item = value}); + return value; + end + end +end + -------------------------------------------------------------------- local actions = {}; |