Add copyright header to those files missing one
[prosody.git] / util / pluginloader.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9
10 local plugin_dir = CFG_PLUGINDIR or "./plugins/";
11
12 local io_open = io.open;
13 local loadstring = loadstring;
14
15 module "pluginloader"
16
17 local function load_file(name)
18         local file, err = io_open(plugin_dir..name);
19         if not file then return file, err; end
20         local content = file:read("*a");
21         file:close();
22         return content, name;
23 end
24
25 function load_resource(plugin, resource)
26         if not resource then
27                 resource = "mod_"..plugin..".lua";
28         end
29         local content, err = load_file(plugin.."/"..resource);
30         if not content then content, err = load_file(resource); end
31         -- TODO add support for packed plugins
32         return content, err;
33 end
34
35 function load_code(plugin, resource)
36         local content, err = load_resource(plugin, resource);
37         if not content then return content, err; end
38         return loadstring(content, "@"..err);
39 end
40
41 return _M;