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.
10 local plugin_dir = CFG_PLUGINDIR or "./plugins/";
12 local io_open, os_time = io.open, os.time;
13 local loadstring, pairs = loadstring, pairs;
15 local datamanager = require "util.datamanager";
19 local function load_file(name)
20 local file, err = io_open(plugin_dir..name);
21 if not file then return file, err; end
22 local content = file:read("*a");
27 function load_resource(plugin, resource, loader)
29 resource = "mod_"..plugin..".lua";
31 loader = loader or load_file;
33 local content, err = loader(plugin.."/"..resource);
34 if not content then content, err = loader(resource); end
35 -- TODO add support for packed plugins
40 function load_code(plugin, resource)
41 local content, err = load_resource(plugin, resource);
42 if not content then return content, err; end
43 return loadstring(content, "@"..err);