mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
Fix #7
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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; }
|
||||
|
Reference in New Issue
Block a user