X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=core%2Fmoduleapi.lua;h=9b773f89c5314ba7e9a0771722869cf69d79d8c3;hb=08b19bb731babd4d3a8697f2e6bbf8b61aa1c3cc;hp=114a97a787727c695e7ec3e6d813106eb85e9459;hpb=a81725f764e9fb73f50008e65b75cdfecbc6d0e3;p=prosody.git diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 114a97a7..9b773f89 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -23,7 +23,7 @@ local ipairs, pairs, select = ipairs, pairs, select; local tonumber, tostring = tonumber, tostring; local require = require; local pack = table.pack or function(...) return {n=select("#",...), ...}; end -- table.pack is only in 5.2 -local unpack = table.unpack or unpack; -- renamed in 5.2 +local unpack = table.unpack or unpack; --luacheck: ignore 113 -- renamed in 5.2 local prosody = prosody; local hosts = prosody.hosts; @@ -137,10 +137,7 @@ function api:wrap_global(event, handler) end function api:require(lib) - local f, n = pluginloader.load_code(self.name, lib..".lib.lua", self.environment); - if not f then - f, n = pluginloader.load_code(lib, lib..".lib.lua", self.environment); - end + local f, n = pluginloader.load_code_ext(self.name, lib, "lib.lua", self.environment); if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message return f(); end @@ -306,6 +303,20 @@ function api:get_option_inherited_set(name, ...) return value; end +function api:get_option_path(name, default, parent) + if parent == nil then + parent = parent or self:get_directory(); + elseif prosody.paths[parent] then + parent = prosody.paths[parent]; + end + local value = self:get_option_string(name, default); + if value == nil then + return nil; + end + return resolve_relative_path(parent, value); +end + + function api:context(host) return setmetatable({host=host or "*"}, {__index=self,__newindex=self}); end @@ -364,8 +375,8 @@ function api:provides(name, item) self:add_item(name.."-provider", item); end -function api:send(stanza) - return core_post_stanza(hosts[self.host], stanza); +function api:send(stanza, origin) + return core_post_stanza(origin or hosts[self.host], stanza); end function api:broadcast(jids, stanza, iter) @@ -388,7 +399,7 @@ function timer_methods:reschedule(delay) timer.reschedule(self.id, delay) end -local function timer_callback(now, id, t) +local function timer_callback(now, id, t) --luacheck: ignore 212/id if t.module_env.loaded == false then return; end return t.callback(now, unpack(t, 1, t.n)); end