From 965d511d529e47590c267312529d926320c9c750 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Thu, 3 Jul 2014 20:20:44 +0300 Subject: [PATCH] Eluna fix load order _ext in file name and .ext as extension can both be used to mark files as extensions that are loaded first. Otherwise all is loaded alphabetically. Everything is loaded as modules, which means that they cant be loaded twice with require. closes #85 --- LuaEngine.cpp | 11 ++++++++--- extensions/{FunctionCache.lua => FunctionCache.ext} | 0 .../{ObjectVariables.lua => ObjectVariables.ext} | 0 extensions/{_Misc.lua => _Misc.ext} | 0 4 files changed, 8 insertions(+), 3 deletions(-) rename extensions/{FunctionCache.lua => FunctionCache.ext} (100%) rename extensions/{ObjectVariables.lua => ObjectVariables.ext} (100%) rename extensions/{_Misc.lua => _Misc.ext} (100%) diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 861351a..dac81e6 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -32,7 +32,7 @@ void Eluna::Initialize() lua_folderpath.replace(0, 1, home); #endif ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", lua_folderpath.c_str()); - GetScripts(lua_folderpath + "/extensions", lua_extensions); + // GetScripts(lua_folderpath + "/extensions", lua_extensions); GetScripts(lua_folderpath, lua_scripts); ELUNA_LOG_DEBUG("[Eluna]: Loaded %u scripts in %u ms", uint32(lua_scripts.size()), GetTimeDiff(oldMSTime)); @@ -183,7 +183,9 @@ void Eluna::GetScripts(std::string path, ScriptList& scripts) filename = filename.substr(0, extDot); // check extension and add path to scripts to load - if (ext != ".lua" && ext != ".dll") + bool luascript = ext == ".lua" || ext == ".dll"; + bool extension = ext == ".ext" || (filename.length() >= 4 && filename.find_last_of("_ext") == filename.length() - 4); + if (!luascript && !extension) continue; LuaScript script; @@ -191,7 +193,10 @@ void Eluna::GetScripts(std::string path, ScriptList& scripts) script.filename = filename; script.filepath = fullpath; script.modulepath = fullpath.substr(0, fullpath.length() - ext.length()); - scripts.push_back(script); + if (extension) + lua_extensions.push_back(script); + else + scripts.push_back(script); ELUNA_LOG_DEBUG("[Eluna]: GetScripts add path `%s`", fullpath.c_str()); } } diff --git a/extensions/FunctionCache.lua b/extensions/FunctionCache.ext similarity index 100% rename from extensions/FunctionCache.lua rename to extensions/FunctionCache.ext diff --git a/extensions/ObjectVariables.lua b/extensions/ObjectVariables.ext similarity index 100% rename from extensions/ObjectVariables.lua rename to extensions/ObjectVariables.ext diff --git a/extensions/_Misc.lua b/extensions/_Misc.ext similarity index 100% rename from extensions/_Misc.lua rename to extensions/_Misc.ext