diff options
author | Waqas Hussain <waqas20@gmail.com> | 2010-07-31 12:32:34 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2010-07-31 12:32:34 +0500 |
commit | 6f80673f10e91e6f2d8f3ed3fcf0c6b30187f839 (patch) | |
tree | 7f62e20f21dbe971776011df121432aed1227269 | |
parent | 95fec897d970e2cae9740d4bce71a56378850ffb (diff) | |
download | prosody-6f80673f10e91e6f2d8f3ed3fcf0c6b30187f839.tar.gz prosody-6f80673f10e91e6f2d8f3ed3fcf0c6b30187f839.zip |
util.pluginloader: Fix loading of plugins, plugin libraries and resources in subfolders (e.g., when loading 'a/b', load 'a/mod_b.lua', and not 'mod_a/b.lua').
-rw-r--r-- | util/pluginloader.lua | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/util/pluginloader.lua b/util/pluginloader.lua index 956b92bd..07b4e5c7 100644 --- a/util/pluginloader.lua +++ b/util/pluginloader.lua @@ -25,16 +25,30 @@ local function load_file(name) end function load_resource(plugin, resource, loader) - if not resource then - resource = "mod_"..plugin..".lua"; + local path, name = plugin:match("([^/]*)/?(.*)"); + if name == "" then + if not resource then + resource = "mod_"..plugin..".lua"; + end + loader = loader or load_file; + + local content, err = loader(plugin.."/"..resource); + if not content then content, err = loader(resource); end + -- TODO add support for packed plugins + + return content, err; + else + if not resource then + resource = "mod_"..name..".lua"; + end + loader = loader or load_file; + + local content, err = loader(plugin.."/"..resource); + if not content then content, err = loader(path.."/"..resource); end + -- TODO add support for packed plugins + + return content, err; end - loader = loader or load_file; - - local content, err = loader(plugin.."/"..resource); - if not content then content, err = loader(resource); end - -- TODO add support for packed plugins - - return content, err; end function load_code(plugin, resource) |