Eluna fix TC errors from previous commits, fix merge and fix a crash on osx

This commit is contained in:
Rochet2
2014-12-15 23:24:51 +02:00
parent 525e108b83
commit 7671054425
7 changed files with 133 additions and 71 deletions

View File

@@ -713,7 +713,7 @@ namespace LuaCreature
std::advance(itr, position);
Eluna::Push(L, *itr);
}
break;
break;
case SELECT_TARGET_FARTHEST:
case SELECT_TARGET_BOTTOMAGGRO:
{
@@ -722,7 +722,7 @@ namespace LuaCreature
std::advance(ritr, position);
Eluna::Push(L, *ritr);
}
break;
break;
case SELECT_TARGET_RANDOM:
{
std::list<Unit*>::const_iterator itr = targetList.begin();
@@ -732,7 +732,7 @@ namespace LuaCreature
std::advance(itr, urand(0, targetList.size() - 1));
Eluna::Push(L, *itr);
}
break;
break;
default:
luaL_argerror(L, 2, "SelectAggroTarget expected");
break;

View File

@@ -51,7 +51,7 @@ ElunaEventProcessor::ElunaEventProcessor(Eluna** _E, WorldObject* _obj) : m_time
ElunaEventProcessor::~ElunaEventProcessor()
{
RemoveEvents();
RemoveEvents_internal();
if (obj)
{
@@ -87,6 +87,12 @@ void ElunaEventProcessor::Update(uint32 diff)
}
void ElunaEventProcessor::RemoveEvents()
{
for (EventList::iterator it = eventList.begin(); it != eventList.end(); ++it)
it->second->to_Abort = true;
}
void ElunaEventProcessor::RemoveEvents_internal()
{
//if (!final)
//{
@@ -125,7 +131,13 @@ EventMgr::EventMgr(Eluna** _E) : globalProcessor(new ElunaEventProcessor(_E, NUL
EventMgr::~EventMgr()
{
RemoveEvents();
{
ReadGuard lock(GetLock());
if (!processors.empty())
for (ProcessorSet::const_iterator it = processors.begin(); it != processors.end(); ++it) // loop processors
(*it)->RemoveEvents_internal();
globalProcessor->RemoveEvents_internal();
}
delete globalProcessor;
globalProcessor = NULL;
}

View File

@@ -45,6 +45,7 @@ private:
class ElunaEventProcessor
{
friend class LuaEvent;
friend class EventMgr;
public:
typedef std::multimap<uint64, LuaEvent*> EventList;
@@ -54,7 +55,7 @@ public:
~ElunaEventProcessor();
void Update(uint32 diff);
// instantly removes all timed events
// removes all timed events on next tick or at tick end
void RemoveEvents();
// set the event to be removed when executing
void RemoveEvent(int eventId);
@@ -62,7 +63,9 @@ public:
EventMap eventMap;
private:
void RemoveEvents_internal();
void AddEvent(LuaEvent* Event);
bool removeAllEvents;
EventList eventList;
uint64 m_time;
WorldObject* obj;

View File

@@ -1435,7 +1435,7 @@ namespace LuaGlobalFunctions
creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase);
uint32 db_lowguid = creature->GetDBTableGUIDLow();
if (!creaturLoadCreatureFromDB(db_lowguid, map))
if (!creature->LoadCreatureFromDB(db_lowguid, map))
{
delete creature;
Eluna::Push(L);
@@ -2260,9 +2260,9 @@ namespace LuaGlobalFunctions
*
* @return uint32 currTime
*/
int GetCurrTime(Eluna* E)
int GetCurrTime(Eluna* /*E*/, lua_State* L)
{
Eluna::Push(E->L, ElunaUtil::GetCurrTime());
Eluna::Push(L, ElunaUtil::GetCurrTime());
return 1;
}
@@ -2272,30 +2272,30 @@ namespace LuaGlobalFunctions
* @param uint32 oldTime
* @return uint32 timeDiff
*/
int GetTimeDiff(Eluna* E)
int GetTimeDiff(Eluna* /*E*/, lua_State* L)
{
uint32 oldtimems = Eluna::CHECKVAL<uint32>(E->L, 1);
uint32 oldtimems = Eluna::CHECKVAL<uint32>(L, 1);
Eluna::Push(E->L, ElunaUtil::GetTimeDiff(oldtimems));
Eluna::Push(L, ElunaUtil::GetTimeDiff(oldtimems));
return 1;
}
std::string GetStackAsString(Eluna* E)
std::string GetStackAsString(lua_State* L)
{
std::ostringstream oss;
for (int i = 1; i <= lua_gettop(E->L); ++i)
oss << luaL_tolstring(E->L, i, NULL);
for (int i = 1; i <= lua_gettop(L); ++i)
oss << luaL_tolstring(L, i, NULL);
return oss.str();
}
/**
* Prints given parameters to the info log
*
* @param ... variableArguments
*/
int PrintInfo(Eluna* E)
int PrintInfo(Eluna* /*E*/, lua_State* L)
{
ELUNA_LOG_INFO("%s", GetStackAsString(E).c_str());
ELUNA_LOG_INFO("%s", GetStackAsString(L).c_str());
return 0;
}
@@ -2304,9 +2304,9 @@ namespace LuaGlobalFunctions
*
* @param ... variableArguments
*/
int PrintError(Eluna* E)
int PrintError(Eluna* /*E*/, lua_State* L)
{
ELUNA_LOG_ERROR("%s", GetStackAsString(E).c_str());
ELUNA_LOG_ERROR("%s", GetStackAsString(L).c_str());
return 0;
}
@@ -2315,9 +2315,9 @@ namespace LuaGlobalFunctions
*
* @param ... variableArguments
*/
int PrintDebug(Eluna* E)
int PrintDebug(Eluna* /*E*/, lua_State* L)
{
ELUNA_LOG_DEBUG("%s", GetStackAsString(E).c_str());
ELUNA_LOG_DEBUG("%s", GetStackAsString(L).c_str());
return 0;
}
}

View File

@@ -1442,15 +1442,6 @@ uint32 Eluna::GetDialogStatus(Player* pPlayer, Creature* pCreature)
return DIALOG_STATUS_SCRIPTED_NO_STATUS;
}
void Eluna::OnSummoned(Creature* pCreature, Unit* pSummoner)
{
ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED, return);
Push(L, pCreature);
Push(L, pSummoner);
ENTRY_EXECUTE(0);
ENDCALL();
}
void Eluna::OnAddToWorld(Creature* creature)
{
ENTRY_BEGIN(CreatureEventBindings, creature->GetEntry(), CREATURE_EVENT_ON_ADD, return);
@@ -1467,6 +1458,22 @@ void Eluna::OnRemoveFromWorld(Creature* creature)
ENDCALL();
}
bool Eluna::OnSummoned(Creature* pCreature, Unit* pSummoner)
{
bool result = false;
ENTRY_BEGIN(CreatureEventBindings, pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED, return false);
Push(L, pCreature);
Push(L, pSummoner);
ENTRY_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
}
bool Eluna::UpdateAI(Creature* me, const uint32 diff)
{
bool result = false;
@@ -1474,8 +1481,10 @@ bool Eluna::UpdateAI(Creature* me, const uint32 diff)
Eluna::Push(L, me);
Eluna::Push(L, diff);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1490,8 +1499,10 @@ bool Eluna::EnterCombat(Creature* me, Unit* target)
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1526,8 +1537,10 @@ bool Eluna::JustDied(Creature* me, Unit* killer)
Eluna::Push(L, me);
Eluna::Push(L, killer);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1541,8 +1554,10 @@ bool Eluna::KilledUnit(Creature* me, Unit* victim)
Eluna::Push(L, me);
Eluna::Push(L, victim);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1556,8 +1571,10 @@ bool Eluna::JustSummoned(Creature* me, Creature* summon)
Eluna::Push(L, me);
Eluna::Push(L, summon);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1571,8 +1588,10 @@ bool Eluna::SummonedCreatureDespawn(Creature* me, Creature* summon)
Eluna::Push(L, me);
Eluna::Push(L, summon);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1587,8 +1606,10 @@ bool Eluna::MovementInform(Creature* me, uint32 type, uint32 id)
Eluna::Push(L, type);
Eluna::Push(L, id);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1602,8 +1623,10 @@ bool Eluna::AttackStart(Creature* me, Unit* target)
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1617,8 +1640,10 @@ bool Eluna::EnterEvadeMode(Creature* me)
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return false);
Eluna::Push(L, me);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1632,8 +1657,10 @@ bool Eluna::AttackedBy(Creature* me, Unit* attacker)
Eluna::Push(L, me);
Eluna::Push(L, attacker);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1647,8 +1674,10 @@ bool Eluna::JustRespawned(Creature* me)
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return false);
Eluna::Push(L, me);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1661,8 +1690,10 @@ bool Eluna::JustReachedHome(Creature* me)
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return false);
Eluna::Push(L, me);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1677,8 +1708,10 @@ bool Eluna::ReceiveEmote(Creature* me, Player* player, uint32 emoteId)
Eluna::Push(L, player);
Eluna::Push(L, emoteId);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1710,8 +1743,10 @@ bool Eluna::MoveInLineOfSight(Creature* me, Unit* who)
Eluna::Push(L, me);
Eluna::Push(L, who);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1735,8 +1770,10 @@ bool Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell)
Eluna::Push(L, caster);
Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1751,8 +1788,10 @@ bool Eluna::SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell)
Eluna::Push(L, target);
Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1768,8 +1807,10 @@ bool Eluna::SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer)
Eluna::Push(L, summon);
Eluna::Push(L, killer);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1783,8 +1824,10 @@ bool Eluna::OwnerAttackedBy(Creature* me, Unit* attacker)
Eluna::Push(L, me);
Eluna::Push(L, attacker);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;
@@ -1798,8 +1841,10 @@ bool Eluna::OwnerAttacked(Creature* me, Unit* target)
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(1);
FOR_RETS(i) {
result = CHECKVAL<bool>(L, i, false);
FOR_RETS(i)
{
if (lua_isboolean(L, i))
result = CHECKVAL<bool>(L, i, false);
}
ENDCALL();
return result;

View File

@@ -248,6 +248,7 @@ void Eluna::GetScripts(std::string path)
lua_requirepath +=
path + "/?;" +
path + "/?.lua;" +
path + "/?.ext;" +
path + "/?.dll;" +
path + "/?.so;";
@@ -290,6 +291,7 @@ void Eluna::GetScripts(std::string path)
lua_requirepath +=
path + "/?;" +
path + "/?.lua;" +
path + "/?.ext;" +
path + "/?.dll;" +
path + "/?.so;";
@@ -373,7 +375,7 @@ void Eluna::RunScripts()
lua_pop(L, 1);
if (!luaL_loadfile(L, it->filepath.c_str()) && !lua_pcall(L, 0, 1, 0))
{
if (!lua_toboolean(L, -1))
if (lua_isnoneornil(L, -1) || (lua_isboolean(L, -1) && !lua_toboolean(L, -1)))
{
lua_pop(L, 1);
Push(L, true);

View File

@@ -225,8 +225,8 @@ public:
bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest);
bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest, uint32 opt);
uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature);
void OnSummoned(Creature* creature, Unit* summoner);
bool OnSummoned(Creature* creature, Unit* summoner);
bool UpdateAI(Creature* me, const uint32 diff);
bool EnterCombat(Creature* me, Unit* target);
bool DamageTaken(Creature* me, Unit* attacker, uint32& damage);