diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-02-01 00:31:05 +0100 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-02-01 00:31:05 +0100 |
commit | fec17409d2f566af18bad269fe2c5c372a474ecb (patch) | |
tree | 93baa2311e38fddb86a68e550955c261ac96cf3b /src/Bindings/PluginLua.cpp | |
parent | Changed signitures of Several BLockHandler Methods (diff) | |
parent | Contributors now match real life, and are alpha-sorted. (diff) | |
download | cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.tar cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.tar.gz cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.tar.bz2 cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.tar.lz cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.tar.xz cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.tar.zst cuberite-fec17409d2f566af18bad269fe2c5c372a474ecb.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/PluginLua.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 1d8c4c6ed..7b2362887 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -88,36 +88,55 @@ bool cPluginLua::Initialize(void) 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()); - - int numFiles = 0; - for (AStringVector::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) + AStringVector LuaFiles; + bool HasInfoLua = false; + 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); + } } + } + std::sort(LuaFiles.begin(), LuaFiles.end()); + + // Warn if there are no Lua files in the plugin folder: + if (LuaFiles.empty()) + { + LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str()); + Close(); + return false; + } + + // 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; - } - else - { - numFiles++; } } // for itr - Files[] - - if (numFiles == 0) + if (HasInfoLua) { - LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str()); - Close(); - return false; + AString Path = PluginPath + "Info.lua"; + if (!m_LuaState.LoadFile(Path)) + { + Close(); + return false; + } } - // Call intialize function + // Call the Initialize function: bool res = false; if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res)) { @@ -125,7 +144,6 @@ bool cPluginLua::Initialize(void) Close(); return false; } - if (!res) { LOGINFO("Plugin %s: Initialize() call failed, plugin is temporarily disabled.", GetName().c_str()); |