Software /
code /
prosody
Comparison
core/modulemanager.lua @ 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 |
parent | 1586:5c627d5d5e37 |
child | 1695:9786e650393b |
comparison
equal
deleted
inserted
replaced
1693:56e23b0b3893 | 1694:0b7888c0995d |
---|---|
420 | 420 |
421 function api:get_option(name, default_value) | 421 function api:get_option(name, default_value) |
422 return config.get(self.host, self.name, name) or config.get(self.host, "core", name) or default_value; | 422 return config.get(self.host, self.name, name) or config.get(self.host, "core", name) or default_value; |
423 end | 423 end |
424 | 424 |
425 local t_remove = _G.table.remove; | |
426 local module_items = multitable_new(); | |
427 function api:add_item(key, value) | |
428 self.items = self.items or {}; | |
429 self.items[key] = self.items[key] or {}; | |
430 t_insert(self.items[key], value); | |
431 self:fire_event("item-added/"..key, {source = self, item = value}); | |
432 end | |
433 function api:remove_item(key, value) | |
434 local t = self.items and self.items[key] or NULL; | |
435 for i = #t,1,-1 do | |
436 if t[i] == value then | |
437 t_remove(self.items[key], i); | |
438 self:fire_event("item-removed/"..key, {source = self, item = value}); | |
439 return value; | |
440 end | |
441 end | |
442 end | |
443 | |
425 -------------------------------------------------------------------- | 444 -------------------------------------------------------------------- |
426 | 445 |
427 local actions = {}; | 446 local actions = {}; |
428 | 447 |
429 function actions.load(params) | 448 function actions.load(params) |