Changeset

1694:0b7888c0995d

Added: functions add_item and remove_item to add and remove items to the module API
author Waqas Hussain <waqas20@gmail.com>
date Tue, 18 Aug 2009 12:30:06 +0500 (2009-08-18)
parents 1693:56e23b0b3893
children 1695:9786e650393b
files core/modulemanager.lua
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 = {};