Software /
code /
prosody
Diff
core/moduleapi.lua @ 4613:27fbc9c69eb5
moduleapi: Add module:provides(), a shortcut to add an item with the current module's name
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 15 Mar 2012 02:52:31 +0000 |
parent | 4605:69746db53125 |
child | 4614:20940729c1b4 |
line wrap: on
line diff
--- a/core/moduleapi.lua Wed Mar 14 23:44:24 2012 +0000 +++ b/core/moduleapi.lua Thu Mar 15 02:52:31 2012 +0000 @@ -292,4 +292,18 @@ 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;