Software / code / prosody
Comparison
core/moduleapi.lua @ 5021:85b2689dbcfe
Eliminate direct setfenv usage
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 08 Jun 2012 05:04:38 +0200 |
| parent | 4896:27cda15104f2 |
| child | 5024:d25e1b9332cc |
comparison
equal
deleted
inserted
replaced
| 5020:ef1eb65acbba | 5021:85b2689dbcfe |
|---|---|
| 15 local timer = require "util.timer"; | 15 local timer = require "util.timer"; |
| 16 | 16 |
| 17 local multitable_new = require "util.multitable".new; | 17 local multitable_new = require "util.multitable".new; |
| 18 | 18 |
| 19 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; | 19 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; |
| 20 local error, setmetatable, setfenv, type = error, setmetatable, setfenv, type; | 20 local error, setmetatable, type = error, setmetatable, type; |
| 21 local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack; | 21 local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack; |
| 22 local tonumber, tostring = tonumber, tostring; | 22 local tonumber, tostring = tonumber, tostring; |
| 23 | 23 |
| 24 local prosody = prosody; | 24 local prosody = prosody; |
| 25 local hosts = prosody.hosts; | 25 local hosts = prosody.hosts; |
| 97 return self:hook("stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); | 97 return self:hook("stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); |
| 98 end | 98 end |
| 99 api.hook_stanza = api.hook_tag; -- COMPAT w/pre-0.9 | 99 api.hook_stanza = api.hook_tag; -- COMPAT w/pre-0.9 |
| 100 | 100 |
| 101 function api:require(lib) | 101 function api:require(lib) |
| 102 local f, n = pluginloader.load_code(self.name, lib..".lib.lua"); | 102 local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); |
| 103 if not f then | 103 if not f then |
| 104 f, n = pluginloader.load_code(lib, lib..".lib.lua"); | 104 f, n = pluginloader.load_code(lib, lib..".lib.lua", self.environment); |
| 105 end | 105 end |
| 106 if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message | 106 if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message |
| 107 setfenv(f, self.environment); | |
| 108 return f(); | 107 return f(); |
| 109 end | 108 end |
| 110 | 109 |
| 111 function api:depends(name) | 110 function api:depends(name) |
| 112 if not self.dependencies then | 111 if not self.dependencies then |