From 6f80673f10e91e6f2d8f3ed3fcf0c6b30187f839 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 31 Jul 2010 12:32:34 +0500 Subject: 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'). --- util/pluginloader.lua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'util/pluginloader.lua') 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) -- cgit v1.2.3