From 6594b2d09037271978458b019f8d6bd550d9d8a7 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sat, 26 Jan 2013 14:54:19 -0200 Subject: [PATCH] Fix #7 --- src/framework/core/module.cpp | 17 ++++++++++++++++- src/framework/core/module.h | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/framework/core/module.cpp b/src/framework/core/module.cpp index e8391428..115d9111 100644 --- a/src/framework/core/module.cpp +++ b/src/framework/core/module.cpp @@ -46,10 +46,16 @@ bool Module::load() g_lua.pop(); for(const std::string& depName : m_dependencies) { + if(depName == m_name) + stdext::throw_exception(stdext::format("cannot depend on itself")); + ModulePtr dep = g_modules.getModule(depName); if(!dep) stdext::throw_exception(stdext::format("dependency '%s' was not found", depName)); + if(dep->hasDependency(m_name, true)) + stdext::throw_exception(stdext::format("dependency '%s' is recursively depending on itself", depName)); + if(!dep->isLoaded() && !dep->load()) stdext::throw_exception(stdext::format("dependency '%s' has failed to load", depName)); } @@ -158,10 +164,19 @@ bool Module::isDependent() return false; } -bool Module::hasDependency(const std::string& name) +bool Module::hasDependency(const std::string& name, bool recursive) { if(std::find(m_dependencies.begin(), m_dependencies.end(), name) != m_dependencies.end()) return true; + + if(recursive) { + for(const std::string& depName : m_dependencies) { + ModulePtr dep = g_modules.getModule(depName); + if(dep && dep->hasDependency(name, true)) + return true; + } + } + return false; } diff --git a/src/framework/core/module.h b/src/framework/core/module.h index e73517a8..900f05c4 100644 --- a/src/framework/core/module.h +++ b/src/framework/core/module.h @@ -44,7 +44,7 @@ public: bool isReloadable() { return m_reloadable; } bool isDependent(); bool isSandboxed() { return m_sandboxed; } - bool hasDependency(const std::string& name); + bool hasDependency(const std::string& name, bool recursive = false); int getSandbox(LuaInterface *lua); std::string getDescription() { return m_description; }