X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=core%2Fmoduleapi.lua;h=402c79275fe0456f2004c2b7aece035329d21dcc;hb=1c8107c16696118e07c456292f02f0d640b4953f;hp=5817894f938e8d88dcad88f085107973ac6244fe;hpb=075dc530172526a2315a6a16b6f7921da8cb2a0f;p=prosody.git diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 5817894f..402c7927 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -19,7 +19,8 @@ local st = require "util.stanza"; local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, type = error, setmetatable, type; -local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack; +local ipairs, pairs, select = ipairs, pairs, select; +local unpack = table.unpack or unpack; --luacheck: ignore 113 local tonumber, tostring = tonumber, tostring; local require = require; @@ -135,10 +136,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 @@ -304,6 +302,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