aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-03-15 02:52:31 +0000
committerMatthew Wild <mwild1@gmail.com>2012-03-15 02:52:31 +0000
commit4090846d760a746e67f19eda59becf291608eff2 (patch)
tree487bb0655cc42c97a13dda1c39bed50626991020
parent591bcc96e66cb00ac85d416899a61733d12cb6f0 (diff)
downloadprosody-4090846d760a746e67f19eda59becf291608eff2.tar.gz
prosody-4090846d760a746e67f19eda59becf291608eff2.zip
moduleapi: Add module:provides(), a shortcut to add an item with the current module's name
-rw-r--r--core/moduleapi.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index b11fd7b3..2177378f 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -292,4 +292,18 @@ function api:handle_items(type, added_cb, removed_cb, existing)
end
end
+function api:provides(name, item)
+ if not item then item = self.environment; end
+ if not item.name then
+ local item_name = module.name;
+ -- Strip a provider prefix to find the item name
+ -- (e.g. "auth_foo" -> "foo" for an auth provider)
+ if item_name:find(name.."_", 1, true) == 1 then
+ item_name = item_name:sub(#name+2);
+ end
+ item.name = item_name;
+ end
+ self:add_item(name, item);
+end
+
return api;