Eduardo Bart 11 years ago
parent 4d0d62e364
commit 6594b2d090

@ -46,10 +46,16 @@ bool Module::load()
g_lua.pop(); g_lua.pop();
for(const std::string& depName : m_dependencies) { 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); ModulePtr dep = g_modules.getModule(depName);
if(!dep) if(!dep)
stdext::throw_exception(stdext::format("dependency '%s' was not found", depName)); 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()) if(!dep->isLoaded() && !dep->load())
stdext::throw_exception(stdext::format("dependency '%s' has failed to load", depName)); stdext::throw_exception(stdext::format("dependency '%s' has failed to load", depName));
} }
@ -158,10 +164,19 @@ bool Module::isDependent()
return false; 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()) if(std::find(m_dependencies.begin(), m_dependencies.end(), name) != m_dependencies.end())
return true; 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; return false;
} }

@ -44,7 +44,7 @@ public:
bool isReloadable() { return m_reloadable; } bool isReloadable() { return m_reloadable; }
bool isDependent(); bool isDependent();
bool isSandboxed() { return m_sandboxed; } bool isSandboxed() { return m_sandboxed; }
bool hasDependency(const std::string& name); bool hasDependency(const std::string& name, bool recursive = false);
int getSandbox(LuaInterface *lua); int getSandbox(LuaInterface *lua);
std::string getDescription() { return m_description; } std::string getDescription() { return m_description; }

Loading…
Cancel
Save