modulemanager, util.pluginloader: Move logic for locating some module libraries to...
authorMatthew Wild <mwild1@gmail.com>
Mon, 1 Feb 2016 21:26:15 +0000 (21:26 +0000)
committerMatthew Wild <mwild1@gmail.com>
Mon, 1 Feb 2016 21:26:15 +0000 (21:26 +0000)
core/moduleapi.lua
util/pluginloader.lua

index 5817894f938e8d88dcad88f085107973ac6244fe..c439ba6f6459d5ee459338b8186d472c67bb8508 100644 (file)
@@ -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
index 0d7eafa7a154122d3af7242bac792349963794b6..004855f092ee7cabb4655b9533b14642ecb685cf 100644 (file)
@@ -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;
 };