util/pluginloader.lua

changeset 3410
32b018eeeb3b
parent 3233
8f78e8164032
child 3411
7170aaeb582d
equal deleted inserted replaced
3409:b2a112720cae 3410:32b018eeeb3b
23 file:close(); 23 file:close();
24 return content, name; 24 return content, name;
25 end 25 end
26 26
27 function load_resource(plugin, resource, loader) 27 function load_resource(plugin, resource, loader)
28 if not resource then 28 local path, name = plugin:match("([^/]*)/?(.*)");
29 resource = "mod_"..plugin..".lua"; 29 if name == "" then
30 if not resource then
31 resource = "mod_"..plugin..".lua";
32 end
33 loader = loader or load_file;
34
35 local content, err = loader(plugin.."/"..resource);
36 if not content then content, err = loader(resource); end
37 -- TODO add support for packed plugins
38
39 return content, err;
40 else
41 if not resource then
42 resource = "mod_"..name..".lua";
43 end
44 loader = loader or load_file;
45
46 local content, err = loader(plugin.."/"..resource);
47 if not content then content, err = loader(path.."/"..resource); end
48 -- TODO add support for packed plugins
49
50 return content, err;
30 end 51 end
31 loader = loader or load_file;
32
33 local content, err = loader(plugin.."/"..resource);
34 if not content then content, err = loader(resource); end
35 -- TODO add support for packed plugins
36
37 return content, err;
38 end 52 end
39 53
40 function load_code(plugin, resource) 54 function load_code(plugin, resource)
41 local content, err = load_resource(plugin, resource); 55 local content, err = load_resource(plugin, resource);
42 if not content then return content, err; end 56 if not content then return content, err; end

mercurial