2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local dir_sep, path_sep = package.config:match("^(%S+)%s(%S+)");
10 local plugin_dir = {};
11 for path in (CFG_PLUGINDIR or "./plugins/"):gsub("[/\\]", dir_sep):gmatch("[^"..path_sep.."]+") do
12 path = path..dir_sep; -- add path separator to path end
13 path = path:gsub(dir_sep..dir_sep.."+", dir_sep); -- coalesce multiple separaters
14 plugin_dir[#plugin_dir + 1] = path;
17 local io_open = io.open;
18 local envload = require "util.envload".envload;
20 local function load_file(names)
21 local file, err, path;
22 for i=1,#plugin_dir do
24 path = plugin_dir[i]..names[j];
25 file, err = io_open(path);
27 local content = file:read("*a");
36 local function load_resource(plugin, resource)
37 resource = resource or "mod_"..plugin..".lua";
40 "mod_"..plugin..dir_sep..plugin..dir_sep..resource; -- mod_hello/hello/mod_hello.lua
41 "mod_"..plugin..dir_sep..resource; -- mod_hello/mod_hello.lua
42 plugin..dir_sep..resource; -- hello/mod_hello.lua
43 resource; -- mod_hello.lua
46 return load_file(names);
49 local function load_code(plugin, resource, env)
50 local content, err = load_resource(plugin, resource);
51 if not content then return content, err; end
53 local f, err = envload(content, "@"..path, env);
54 if not f then return f, err; end
58 local function load_code_ext(plugin, resource, extension, env)
59 local content, err = load_resource(plugin, resource.."."..extension);
61 content, err = load_resource(resource, resource.."."..extension);
67 local f, err = envload(content, "@"..path, env);
68 if not f then return f, err; end
73 load_file = load_file;
74 load_resource = load_resource;
75 load_code = load_code;
76 load_code_ext = load_code_ext;