X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fpluginloader.lua;h=b9b3e207fa685ffbf38dbc4f474567fd7a81f6a8;hb=95dfe4b0aaaf26ee4651c09eb9757c56210a135a;hp=555e41bf82b176ab001a4b5d07d6a3c60e3b1457;hpb=f51acb6f7c09072e06152f517a9f782e053677f1;p=prosody.git diff --git a/util/pluginloader.lua b/util/pluginloader.lua index 555e41bf..b9b3e207 100644 --- a/util/pluginloader.lua +++ b/util/pluginloader.lua @@ -1,7 +1,7 @@ -- Prosody IM -- Copyright (C) 2008-2010 Matthew Wild -- Copyright (C) 2008-2010 Waqas Hussain --- +-- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. -- @@ -14,12 +14,12 @@ for path in (CFG_PLUGINDIR or "./plugins/"):gsub("[/\\]", dir_sep):gmatch("[^".. plugin_dir[#plugin_dir + 1] = path; end -local io_open, os_time = io.open, os.time; -local loadstring, pairs = loadstring, pairs; +local io_open = io.open; +local envload = require "util.envload".envload; module "pluginloader" -local function load_file(names) +function load_file(names) local file, err, path; for i=1,#plugin_dir do for j=1,#names do @@ -39,20 +39,20 @@ function load_resource(plugin, resource) resource = resource or "mod_"..plugin..".lua"; local names = { - "mod_"..plugin.."/"..plugin.."/"..resource; -- mod_hello/hello/mod_hello.lua - "mod_"..plugin.."/"..resource; -- mod_hello/mod_hello.lua - plugin.."/"..resource; -- hello/mod_hello.lua - resource; -- mod_hello.lua + "mod_"..plugin..dir_sep..plugin..dir_sep..resource; -- mod_hello/hello/mod_hello.lua + "mod_"..plugin..dir_sep..resource; -- mod_hello/mod_hello.lua + plugin..dir_sep..resource; -- hello/mod_hello.lua + resource; -- mod_hello.lua }; return load_file(names); end -function load_code(plugin, resource) +function load_code(plugin, resource, env) local content, err = load_resource(plugin, resource); if not content then return content, err; end local path = err; - local f, err = loadstring(content, "@"..path); + local f, err = envload(content, "@"..path, env); if not f then return f, err; end return f, path; end