From 3900d20a7cacdfc3c9c72e0da7836954ef6a3511 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:30:06 +0500 Subject: Added: functions add_item and remove_item to add and remove items to the module API --- core/modulemanager.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 = {}; -- cgit v1.2.3