From 924997603fed1d05a5b79060de97cd529aba3c5d Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Sat, 19 Apr 2014 15:38:48 +0300 Subject: [PATCH] Eluna misc fixes --- LuaEngine.cpp | 31 +++++++++++++++---------------- LuaEngine.h | 11 +++++++---- extensions/Misc.lua | 4 ++++ extensions/Randomize.lua | 1 - 4 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 extensions/Misc.lua delete mode 100644 extensions/Randomize.lua diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 7ff04fd..38969f5 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -33,7 +33,7 @@ bool StartEluna() { restart = true; sHookMgr->OnEngineRestart(); - TC_LOG_INFO("eluna", "[Eluna]: Shutting Lua Engine"); + ELUNA_LOG_INFO("[Eluna]: Stopping Lua Engine"); // Unregisters and stops all timed events sEluna->m_EventMgr.RemoveEvents(); @@ -68,7 +68,7 @@ bool StartEluna() } #endif - TC_LOG_INFO("eluna", "[Eluna]: Starting Lua Engine"); + ELUNA_LOG_INFO("[Eluna]: Starting Lua Engine"); sEluna->L = luaL_newstate(); luaL_openlibs(sEluna->L); @@ -76,6 +76,7 @@ bool StartEluna() ScriptPaths scripts; sEluna->GetScripts("lua_scripts", scripts); + sEluna->GetScripts("lua_scripts\\extensions", scripts); sEluna->RunScripts(scripts); /* @@ -115,8 +116,8 @@ void Eluna::GetScripts(std::string path, ScriptPaths& scripts) ACE_Dirent dir; if (dir.open(path.c_str()) == -1) { - TC_LOG_ERROR("eluna", "[Eluna]: Error No `lua_scripts` directory found! Creating a 'lua_scripts' directory."); - ACE_OS::mkdir("lua_scripts"); + ELUNA_LOG_ERROR("[Eluna]: Error No `%s` directory found, creating it", path.c_str()); + ACE_OS::mkdir(path.c_str()); return; } @@ -141,30 +142,33 @@ void Eluna::GetScripts(std::string path, ScriptPaths& scripts) } // was file, check extension - if (fullpath.substr(fullpath.length() - 4, 4) != ".lua") + std::string ext = fullpath.substr(fullpath.length() - 4, 4); + if (ext != ".lua" && ext != ".dll") continue; // was correct, add path to scripts to load - scripts.push_back(fullpath); + scripts.erase(fullpath); + scripts.insert(fullpath); } } void Eluna::RunScripts(ScriptPaths& scripts) { uint32 count = 0; - for (ScriptPaths::const_iterator it = scripts.begin(); it != scripts.end(); ++it) + // load last first to load extensions first + for (ScriptPaths::const_reverse_iterator it = scripts.rbegin(); it != scripts.rend(); ++it) { if (!luaL_loadfile(L, it->c_str()) && !lua_pcall(L, 0, 0, 0)) { // successfully loaded and ran file - TC_LOG_DEBUG("eluna", "[Eluna]: Successfully loaded `%s`.", it->c_str()); + ELUNA_LOG_DEBUG("[Eluna]: Successfully loaded `%s`.", it->c_str()); ++count; continue; } - TC_LOG_ERROR("eluna", "[Eluna]: Error loading file `%s`.", it->c_str()); + ELUNA_LOG_ERROR("[Eluna]: Error loading file `%s`.", it->c_str()); report(L); } - TC_LOG_INFO("eluna", "[Eluna]: Loaded %u Lua scripts..", count); + ELUNA_LOG_INFO("[Eluna]: Loaded %u Lua scripts..", count); } void Eluna::report(lua_State* L) @@ -173,7 +177,7 @@ void Eluna::report(lua_State* L) while (msg) { lua_pop(L, -1); - TC_LOG_ERROR("eluna", "%s", msg); + ELUNA_LOG_ERROR("%s", msg); msg = lua_tostring(L, -1); } } @@ -677,11 +681,6 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) return; } break; - - default: - luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); - luaL_error(L, "Unknown register type (regtype %d, id %d, event %d)", regtype, id, evt); - return; } luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt); diff --git a/LuaEngine.h b/LuaEngine.h index 277849c..0aa77ec 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -63,7 +63,7 @@ extern "C" #include "ArenaTeam.h" #endif -typedef std::vector ScriptPaths; +typedef std::set ScriptPaths; #ifdef MANGOS #undef sWorld @@ -82,9 +82,9 @@ typedef std::vector ScriptPaths; #define GET_GUID GetObjectGuid #define GetGameObjectTemplate GetGameObjectInfo #define GetItemTemplate GetItemPrototype -#define TC_LOG_INFO(L, ...) sLog.outString(__VA_ARGS__); -#define TC_LOG_ERROR(L, ...) sLog.outErrorEluna(__VA_ARGS__); -#define TC_LOG_DEBUG(L, ...) sLog.outDebug(__VA_ARGS__); +#define ELUNA_LOG_INFO(...) sLog.outString(__VA_ARGS__); +#define ELUNA_LOG_ERROR(...) sLog.outErrorEluna(__VA_ARGS__); +#define ELUNA_LOG_DEBUG(...) sLog.outDebug(__VA_ARGS__); #define CORE_VERSION REVISION_NR #define CORE_NAME "MaNGOS" #define SERVER_MSG_STRING SERVER_MSG_CUSTOM @@ -126,6 +126,9 @@ typedef uint64 ObjectGuid; #define CORE_VERSION _DATE #define CORE_NAME "TrinityCore" #define REGEN_TIME_FULL +#define ELUNA_LOG_INFO(...) TC_LOG_INFO("eluna", __VA_ARGS__); +#define ELUNA_LOG_ERROR(...) TC_LOG_ERROR("eluna", __VA_ARGS__); +#define ELUNA_LOG_DEBUG(...) TC_LOG_DEBUG("eluna", __VA_ARGS__); typedef ThreatContainer::StorageType ThreatList; #ifdef CATA #define NUM_MSG_TYPES NUM_OPCODE_HANDLERS diff --git a/extensions/Misc.lua b/extensions/Misc.lua new file mode 100644 index 0000000..f389776 --- /dev/null +++ b/extensions/Misc.lua @@ -0,0 +1,4 @@ +-- Set correct require paths +package.path = package.path.."lua_scripts\\?;lua_scripts\\?.dll;lua_scripts\\?.lua;lua_scripts\\extensions\\?;lua_scripts\\extensions\\?.dll;lua_scripts\\extensions\\?.lua" +-- Randomize random +math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) diff --git a/extensions/Randomize.lua b/extensions/Randomize.lua deleted file mode 100644 index 912f29c..0000000 --- a/extensions/Randomize.lua +++ /dev/null @@ -1 +0,0 @@ -math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) \ No newline at end of file