# HG changeset patch # User Waqas Hussain # Date 1250580606 -18000 # Node ID 0b7888c0995d4aac8d6da4ced395af922eb733d5 # Parent 56e23b0b389300dd72ca04a4da6287ad8fb6d650 Added: functions add_item and remove_item to add and remove items to the module API diff -r 56e23b0b3893 -r 0b7888c0995d core/modulemanager.lua --- a/core/modulemanager.lua Tue Aug 18 12:25:59 2009 +0500 +++ b/core/modulemanager.lua Tue Aug 18 12:30:06 2009 +0500 @@ -422,6 +422,25 @@ 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 = {};