comparison util/pluginloader.lua @ 11200:bf8f2da84007

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 05 Nov 2020 22:31:25 +0100
parents 40abef01f4b9
children e157e5c79daa
comparison
equal deleted inserted replaced
11199:6c7c50a4de32 11200:bf8f2da84007
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 -- luacheck: ignore 113/CFG_PLUGINDIR 8 -- luacheck: ignore 113/CFG_PLUGINDIR
9 9
10 local dir_sep, path_sep = package.config:match("^(%S+)%s(%S+)"); 10 local dir_sep, path_sep = package.config:match("^(%S+)%s(%S+)");
11 local lua_version = _VERSION:match(" (.+)$");
11 local plugin_dir = {}; 12 local plugin_dir = {};
12 for path in (CFG_PLUGINDIR or "./plugins/"):gsub("[/\\]", dir_sep):gmatch("[^"..path_sep.."]+") do 13 for path in (CFG_PLUGINDIR or "./plugins/"):gsub("[/\\]", dir_sep):gmatch("[^"..path_sep.."]+") do
13 path = path..dir_sep; -- add path separator to path end 14 path = path..dir_sep; -- add path separator to path end
14 path = path:gsub(dir_sep..dir_sep.."+", dir_sep); -- coalesce multiple separaters 15 path = path:gsub(dir_sep..dir_sep.."+", dir_sep); -- coalesce multiple separaters
15 plugin_dir[#plugin_dir + 1] = path; 16 plugin_dir[#plugin_dir + 1] = path;
34 return file, err; 35 return file, err;
35 end 36 end
36 37
37 local function load_resource(plugin, resource) 38 local function load_resource(plugin, resource)
38 resource = resource or "mod_"..plugin..".lua"; 39 resource = resource or "mod_"..plugin..".lua";
39
40 local names = { 40 local names = {
41 "mod_"..plugin..dir_sep..plugin..dir_sep..resource; -- mod_hello/hello/mod_hello.lua 41 "mod_"..plugin..dir_sep..plugin..dir_sep..resource; -- mod_hello/hello/mod_hello.lua
42 "mod_"..plugin..dir_sep..resource; -- mod_hello/mod_hello.lua 42 "mod_"..plugin..dir_sep..resource; -- mod_hello/mod_hello.lua
43 plugin..dir_sep..resource; -- hello/mod_hello.lua 43 plugin..dir_sep..resource; -- hello/mod_hello.lua
44 resource; -- mod_hello.lua 44 resource; -- mod_hello.lua
45 "share"..dir_sep.."lua"..dir_sep..lua_version..dir_sep..resource;
46 "share"..dir_sep.."lua"..dir_sep..lua_version..dir_sep.."mod_"..plugin..dir_sep..resource;
45 }; 47 };
46 48
47 return load_file(names); 49 return load_file(names);
48 end 50 end
49 51
56 return f, path; 58 return f, path;
57 end 59 end
58 60
59 local function load_code_ext(plugin, resource, extension, env) 61 local function load_code_ext(plugin, resource, extension, env)
60 local content, err = load_resource(plugin, resource.."."..extension); 62 local content, err = load_resource(plugin, resource.."."..extension);
63 if not content and extension == "lib.lua" then
64 content, err = load_resource(plugin, resource..".lua");
65 end
61 if not content then 66 if not content then
62 content, err = load_resource(resource, resource.."."..extension); 67 content, err = load_resource(resource, resource.."."..extension);
63 if not content then 68 if not content then
64 return content, err; 69 return content, err;
65 end 70 end