From 0fd4fbd94508c689a7a22bea0b1a1041807b1565 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Fri, 25 Apr 2014 11:25:15 +0300 Subject: [PATCH] Eluna fix folder path and add config option possibility for script folder path (default 'lua_scripts') --- LuaEngine.cpp | 16 ++++++++++++---- LuaEngine.h | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/LuaEngine.cpp b/LuaEngine.cpp index e2294e4..5914be0 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -7,6 +7,7 @@ #include #include #include "LuaEngine.h" +#include "Config.h" #ifdef MANGOS INSTANTIATE_SINGLETON_1(Eluna); @@ -75,8 +76,15 @@ bool StartEluna() RegisterFunctions(sEluna->L); ScriptPaths scripts; - sEluna->GetScripts("lua_scripts", scripts); - sEluna->GetScripts("lua_scripts/extensions", scripts); + std::string folderpath = sConfigMgr->GetStringDefault("Eluna.ScriptPath", "lua_scripts"); +#if PLATFORM == PLATFORM_UNIX || PLATFORM == PLATFORM_APPLE + if (folderpath[0] == '~') + if (const char* home = getenv("HOME");) + folderpath.replace(0, 1, home); +#endif + ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", folderpath.c_str()); + sEluna->GetScripts(folderpath, scripts); + sEluna->GetScripts(folderpath+"/extensions", scripts); sEluna->RunScripts(scripts); /* @@ -113,7 +121,7 @@ bool StartEluna() // Finds lua script files from given path (including subdirectories) and pushes them to scripts void Eluna::GetScripts(std::string path, ScriptPaths& scripts) { - ELUNA_LOG_DEBUG("Eluna::GetScripts from path `%s`", path.c_str()); + ELUNA_LOG_DEBUG("[Eluna]: GetScripts from path `%s`", path.c_str()); ACE_Dirent dir; if (dir.open(path.c_str()) == -1) @@ -130,7 +138,7 @@ void Eluna::GetScripts(std::string path, ScriptPaths& scripts) if (ACE::isdotdir(directory->d_name)) continue; - std::string fullpath = path + "\\" + directory->d_name; + std::string fullpath = path + "/" + directory->d_name; ACE_stat stat_buf; if (ACE_OS::lstat(fullpath.c_str(), &stat_buf) == -1) diff --git a/LuaEngine.h b/LuaEngine.h index 2a97c36..e114441 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -68,12 +68,14 @@ typedef std::set ScriptPaths; #ifdef MANGOS #undef sWorld #undef sMapMgr +#undef sConfigMgr #undef sGuildMgr #undef sObjectMgr #undef sAccountMgr #undef sObjectAccessor #define sWorld (&MaNGOS::Singleton::Instance()) #define sMapMgr (&MapManager::Instance()) +#define SConfigMgr (&MaNGOS::Singleton::Instance()) #define sGuildMgr (&MaNGOS::Singleton::Instance()) #define sObjectMgr (&MaNGOS::Singleton::Instance()) #define sAccountMgr (&MaNGOS::Singleton::Instance())