Eluna misc fixes

This commit is contained in:
Rochet2
2014-04-19 15:38:48 +03:00
committed by Foereaper
parent 15134e2771
commit 924997603f
4 changed files with 26 additions and 21 deletions

View File

@@ -33,7 +33,7 @@ bool StartEluna()
{ {
restart = true; restart = true;
sHookMgr->OnEngineRestart(); sHookMgr->OnEngineRestart();
TC_LOG_INFO("eluna", "[Eluna]: Shutting Lua Engine"); ELUNA_LOG_INFO("[Eluna]: Stopping Lua Engine");
// Unregisters and stops all timed events // Unregisters and stops all timed events
sEluna->m_EventMgr.RemoveEvents(); sEluna->m_EventMgr.RemoveEvents();
@@ -68,7 +68,7 @@ bool StartEluna()
} }
#endif #endif
TC_LOG_INFO("eluna", "[Eluna]: Starting Lua Engine"); ELUNA_LOG_INFO("[Eluna]: Starting Lua Engine");
sEluna->L = luaL_newstate(); sEluna->L = luaL_newstate();
luaL_openlibs(sEluna->L); luaL_openlibs(sEluna->L);
@@ -76,6 +76,7 @@ bool StartEluna()
ScriptPaths scripts; ScriptPaths scripts;
sEluna->GetScripts("lua_scripts", scripts); sEluna->GetScripts("lua_scripts", scripts);
sEluna->GetScripts("lua_scripts\\extensions", scripts);
sEluna->RunScripts(scripts); sEluna->RunScripts(scripts);
/* /*
@@ -115,8 +116,8 @@ void Eluna::GetScripts(std::string path, ScriptPaths& scripts)
ACE_Dirent dir; ACE_Dirent dir;
if (dir.open(path.c_str()) == -1) if (dir.open(path.c_str()) == -1)
{ {
TC_LOG_ERROR("eluna", "[Eluna]: Error No `lua_scripts` directory found! Creating a 'lua_scripts' directory."); ELUNA_LOG_ERROR("[Eluna]: Error No `%s` directory found, creating it", path.c_str());
ACE_OS::mkdir("lua_scripts"); ACE_OS::mkdir(path.c_str());
return; return;
} }
@@ -141,30 +142,33 @@ void Eluna::GetScripts(std::string path, ScriptPaths& scripts)
} }
// was file, check extension // 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; continue;
// was correct, add path to scripts to load // was correct, add path to scripts to load
scripts.push_back(fullpath); scripts.erase(fullpath);
scripts.insert(fullpath);
} }
} }
void Eluna::RunScripts(ScriptPaths& scripts) void Eluna::RunScripts(ScriptPaths& scripts)
{ {
uint32 count = 0; 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)) if (!luaL_loadfile(L, it->c_str()) && !lua_pcall(L, 0, 0, 0))
{ {
// successfully loaded and ran file // 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; ++count;
continue; 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); 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) void Eluna::report(lua_State* L)
@@ -173,7 +177,7 @@ void Eluna::report(lua_State* L)
while (msg) while (msg)
{ {
lua_pop(L, -1); lua_pop(L, -1);
TC_LOG_ERROR("eluna", "%s", msg); ELUNA_LOG_ERROR("%s", msg);
msg = lua_tostring(L, -1); msg = lua_tostring(L, -1);
} }
} }
@@ -677,11 +681,6 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef)
return; return;
} }
break; 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_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef);
luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt); luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt);

View File

@@ -63,7 +63,7 @@ extern "C"
#include "ArenaTeam.h" #include "ArenaTeam.h"
#endif #endif
typedef std::vector<std::string> ScriptPaths; typedef std::set<std::string> ScriptPaths;
#ifdef MANGOS #ifdef MANGOS
#undef sWorld #undef sWorld
@@ -82,9 +82,9 @@ typedef std::vector<std::string> ScriptPaths;
#define GET_GUID GetObjectGuid #define GET_GUID GetObjectGuid
#define GetGameObjectTemplate GetGameObjectInfo #define GetGameObjectTemplate GetGameObjectInfo
#define GetItemTemplate GetItemPrototype #define GetItemTemplate GetItemPrototype
#define TC_LOG_INFO(L, ...) sLog.outString(__VA_ARGS__); #define ELUNA_LOG_INFO(...) sLog.outString(__VA_ARGS__);
#define TC_LOG_ERROR(L, ...) sLog.outErrorEluna(__VA_ARGS__); #define ELUNA_LOG_ERROR(...) sLog.outErrorEluna(__VA_ARGS__);
#define TC_LOG_DEBUG(L, ...) sLog.outDebug(__VA_ARGS__); #define ELUNA_LOG_DEBUG(...) sLog.outDebug(__VA_ARGS__);
#define CORE_VERSION REVISION_NR #define CORE_VERSION REVISION_NR
#define CORE_NAME "MaNGOS" #define CORE_NAME "MaNGOS"
#define SERVER_MSG_STRING SERVER_MSG_CUSTOM #define SERVER_MSG_STRING SERVER_MSG_CUSTOM
@@ -126,6 +126,9 @@ typedef uint64 ObjectGuid;
#define CORE_VERSION _DATE #define CORE_VERSION _DATE
#define CORE_NAME "TrinityCore" #define CORE_NAME "TrinityCore"
#define REGEN_TIME_FULL #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; typedef ThreatContainer::StorageType ThreatList;
#ifdef CATA #ifdef CATA
#define NUM_MSG_TYPES NUM_OPCODE_HANDLERS #define NUM_MSG_TYPES NUM_OPCODE_HANDLERS

4
extensions/Misc.lua Normal file
View File

@@ -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)))

View File

@@ -1 +0,0 @@
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6)))