Software / code / prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
| 4612:8bb93860fe46 | 4613:27fbc9c69eb5 |
|---|---|
| 290 added_cb({ item = item }); | 290 added_cb({ item = item }); |
| 291 end | 291 end |
| 292 end | 292 end |
| 293 end | 293 end |
| 294 | 294 |
| 295 function api:provides(name, item) | |
| 296 if not item then item = self.environment; end | |
| 297 if not item.name then | |
| 298 local item_name = module.name; | |
| 299 -- Strip a provider prefix to find the item name | |
| 300 -- (e.g. "auth_foo" -> "foo" for an auth provider) | |
| 301 if item_name:find(name.."_", 1, true) == 1 then | |
| 302 item_name = item_name:sub(#name+2); | |
| 303 end | |
| 304 item.name = item_name; | |
| 305 end | |
| 306 self:add_item(name, item); | |
| 307 end | |
| 308 | |
| 295 return api; | 309 return api; |