aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2016-02-01 21:26:15 +0000
committerMatthew Wild <mwild1@gmail.com>2016-02-01 21:26:15 +0000
commita1e077c5e7d4f6d2768c47a6847fbe8eea0f28d8 (patch)
tree4a2c3c9a40482459f4188df23e24ec989029b46c
parentd920df1dfb4aef67da792686e969249a72ff5f21 (diff)
downloadprosody-a1e077c5e7d4f6d2768c47a6847fbe8eea0f28d8.tar.gz
prosody-a1e077c5e7d4f6d2768c47a6847fbe8eea0f28d8.zip
modulemanager, util.pluginloader: Move logic for locating some module libraries to pluginloader, to fix problems with non-filesystem errors being masked by the second load_code call
-rw-r--r--core/moduleapi.lua5
-rw-r--r--util/pluginloader.lua15
2 files changed, 16 insertions, 4 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 5817894f..c439ba6f 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -135,10 +135,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
diff --git a/util/pluginloader.lua b/util/pluginloader.lua
index 0d7eafa7..004855f0 100644
--- a/util/pluginloader.lua
+++ b/util/pluginloader.lua
@@ -55,8 +55,23 @@ local function load_code(plugin, resource, env)
return f, path;
end
+local function load_code_ext(plugin, resource, extension, env)
+ local content, err = load_resource(plugin, resource.."."..extension);
+ if not content then
+ content, err = load_resource(resource, resource.."."..extension);
+ if not content then
+ return content, err;
+ end
+ end
+ local path = err;
+ local f, err = envload(content, "@"..path, env);
+ if not f then return f, err; end
+ return f, path;
+end
+
return {
load_file = load_file;
load_resource = load_resource;
load_code = load_code;
+ load_code_ext = load_code_ext;
};