diff options
author | Matthew Wild <mwild1@gmail.com> | 2012-03-15 02:52:31 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2012-03-15 02:52:31 +0000 |
commit | 775261ef27a572da6e1c1ccacf79f59f6ead58ef (patch) | |
tree | 487bb0655cc42c97a13dda1c39bed50626991020 | |
parent | 7366c85253a3e1dddb35f8eea2c2fd45996c7f1b (diff) | |
download | prosody-775261ef27a572da6e1c1ccacf79f59f6ead58ef.tar.gz prosody-775261ef27a572da6e1c1ccacf79f59f6ead58ef.zip |
moduleapi: Add module:provides(), a shortcut to add an item with the current module's name
-rw-r--r-- | core/moduleapi.lua | 14 |
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; |