Software /
code /
prosody
Diff
util/pluginloader.lua @ 3410:32b018eeeb3b
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').
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 31 Jul 2010 12:32:34 +0500 |
parent | 3233:8f78e8164032 |
child | 3411:7170aaeb582d |
line wrap: on
line diff
--- a/util/pluginloader.lua Mon Jul 26 13:40:00 2010 +0100 +++ b/util/pluginloader.lua Sat Jul 31 12:32:34 2010 +0500 @@ -25,16 +25,30 @@ end function load_resource(plugin, resource, loader) - if not resource then - resource = "mod_"..plugin..".lua"; - end - loader = loader or load_file; + 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; + 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 end function load_code(plugin, resource)