Comparison

util/pluginloader.lua @ 4121:ea7e3f22f898

util.pluginloader: Add support for multiple plugin directories.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 21 Jan 2011 04:35:49 +0500
parent 3411:7170aaeb582d
child 4149:3c1b153c2856
comparison
equal deleted inserted replaced
4120:d62a2861f1f9 4121:ea7e3f22f898
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 9 local dir_sep, path_sep = package.config:match("^(%S+)%s(%S+)");
10 local plugin_dir = CFG_PLUGINDIR or "./plugins/"; 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;
15 end
11 16
12 local io_open, os_time = io.open, os.time; 17 local io_open, os_time = io.open, os.time;
13 local loadstring, pairs = loadstring, pairs; 18 local loadstring, pairs = loadstring, pairs;
14 19
15 module "pluginloader" 20 module "pluginloader"
16 21
17 local function load_file(name) 22 local function load_file(name)
18 local file, err = io_open(plugin_dir..name); 23 local file, err;
24 for i=1,#plugin_dir do
25 file, err = io_open(plugin_dir[i]..name);
26 if file then break; end
27 end
19 if not file then return file, err; end 28 if not file then return file, err; end
20 local content = file:read("*a"); 29 local content = file:read("*a");
21 file:close(); 30 file:close();
22 return content, name; 31 return content, name;
23 end 32 end