Plugin files are loaded in alphabetical order.
Except for the Info.lua file which gets loaded always last. Implements #597.
This commit is contained in:
parent
4d53eb2711
commit
e40c5a20c8
@ -88,36 +88,55 @@ bool cPluginLua::Initialize(void)
|
|||||||
|
|
||||||
std::string PluginPath = FILE_IO_PREFIX + GetLocalFolder() + "/";
|
std::string PluginPath = FILE_IO_PREFIX + GetLocalFolder() + "/";
|
||||||
|
|
||||||
// Load all files for this plugin, and execute them
|
// List all Lua files for this plugin. Info.lua has a special handling - make it the last to load:
|
||||||
AStringVector Files = cFile::GetFolderContents(PluginPath.c_str());
|
AStringVector Files = cFile::GetFolderContents(PluginPath.c_str());
|
||||||
|
AStringVector LuaFiles;
|
||||||
int numFiles = 0;
|
bool HasInfoLua = false;
|
||||||
for (AStringVector::const_iterator itr = Files.begin(); itr != Files.end(); ++itr)
|
for (AStringVector::const_iterator itr = Files.begin(), end = Files.end(); itr != end; ++itr)
|
||||||
{
|
{
|
||||||
if (itr->rfind(".lua") == AString::npos)
|
if (itr->rfind(".lua") != AString::npos)
|
||||||
{
|
{
|
||||||
continue;
|
if (*itr == "Info.lua")
|
||||||
|
{
|
||||||
|
HasInfoLua = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LuaFiles.push_back(*itr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AString Path = PluginPath + *itr;
|
}
|
||||||
if (!m_LuaState.LoadFile(Path))
|
std::sort(LuaFiles.begin(), LuaFiles.end());
|
||||||
{
|
|
||||||
Close();
|
// Warn if there are no Lua files in the plugin folder:
|
||||||
return false;
|
if (LuaFiles.empty())
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
numFiles++;
|
|
||||||
}
|
|
||||||
} // for itr - Files[]
|
|
||||||
|
|
||||||
if (numFiles == 0)
|
|
||||||
{
|
{
|
||||||
LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str());
|
LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str());
|
||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call intialize function
|
// Load all files in the list, including the Info.lua as last, if it exists:
|
||||||
|
for (AStringVector::const_iterator itr = LuaFiles.begin(), end = LuaFiles.end(); itr != end; ++itr)
|
||||||
|
{
|
||||||
|
AString Path = PluginPath + *itr;
|
||||||
|
if (!m_LuaState.LoadFile(Path))
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // for itr - Files[]
|
||||||
|
if (HasInfoLua)
|
||||||
|
{
|
||||||
|
AString Path = PluginPath + "Info.lua";
|
||||||
|
if (!m_LuaState.LoadFile(Path))
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the Initialize function:
|
||||||
bool res = false;
|
bool res = false;
|
||||||
if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res))
|
if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res))
|
||||||
{
|
{
|
||||||
@ -125,7 +144,6 @@ bool cPluginLua::Initialize(void)
|
|||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
LOGINFO("Plugin %s: Initialize() call failed, plugin is temporarily disabled.", GetName().c_str());
|
LOGINFO("Plugin %s: Initialize() call failed, plugin is temporarily disabled.", GetName().c_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user