Eluna implement changes from new_mthread to master ~ Does not add multithread support

This commit is contained in:
Rochet2
2014-11-30 01:37:45 +02:00
parent a7f4954fbe
commit 6268216a64
27 changed files with 3331 additions and 3000 deletions

View File

@@ -24,9 +24,9 @@ namespace LuaAura
* *
* @return [Unit] caster * @return [Unit] caster
*/ */
int GetCaster(lua_State* L, Aura* aura) int GetCaster(Eluna* E, Aura* aura)
{ {
Eluna::Push(L, aura->GetCaster()); Eluna::Push(E->L, aura->GetCaster());
return 1; return 1;
} }
@@ -35,12 +35,12 @@ namespace LuaAura
* *
* @return string caster_guid : the GUID of the Unit as a decimal string * @return string caster_guid : the GUID of the Unit as a decimal string
*/ */
int GetCasterGUID(lua_State* L, Aura* aura) int GetCasterGUID(Eluna* E, Aura* aura)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, aura->GetCasterGuid()); Eluna::Push(E->L, aura->GetCasterGuid());
#else #else
Eluna::Push(L, aura->GetCasterGUID()); Eluna::Push(E->L, aura->GetCasterGUID());
#endif #endif
return 1; return 1;
} }
@@ -50,9 +50,9 @@ namespace LuaAura
* *
* @return uint32 caster_level * @return uint32 caster_level
*/ */
int GetCasterLevel(lua_State* L, Aura* aura) int GetCasterLevel(Eluna* E, Aura* aura)
{ {
Eluna::Push(L, aura->GetCaster()->getLevel()); Eluna::Push(E->L, aura->GetCaster()->getLevel());
return 1; return 1;
} }
@@ -61,12 +61,12 @@ namespace LuaAura
* *
* @return int32 duration : amount of time left in milliseconds * @return int32 duration : amount of time left in milliseconds
*/ */
int GetDuration(lua_State* L, Aura* aura) int GetDuration(Eluna* E, Aura* aura)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, aura->GetAuraDuration()); Eluna::Push(E->L, aura->GetAuraDuration());
#else #else
Eluna::Push(L, aura->GetDuration()); Eluna::Push(E->L, aura->GetDuration());
#endif #endif
return 1; return 1;
} }
@@ -76,9 +76,9 @@ namespace LuaAura
* *
* @return uint32 aura_id * @return uint32 aura_id
*/ */
int GetAuraId(lua_State* L, Aura* aura) int GetAuraId(Eluna* E, Aura* aura)
{ {
Eluna::Push(L, aura->GetId()); Eluna::Push(E->L, aura->GetId());
return 1; return 1;
} }
@@ -90,12 +90,12 @@ namespace LuaAura
* *
* @return int32 max_duration : the maximum duration of the Aura, in milliseconds * @return int32 max_duration : the maximum duration of the Aura, in milliseconds
*/ */
int GetMaxDuration(lua_State* L, Aura* aura) int GetMaxDuration(Eluna* E, Aura* aura)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, aura->GetAuraMaxDuration()); Eluna::Push(E->L, aura->GetAuraMaxDuration());
#else #else
Eluna::Push(L, aura->GetMaxDuration()); Eluna::Push(E->L, aura->GetMaxDuration());
#endif #endif
return 1; return 1;
} }
@@ -107,9 +107,9 @@ namespace LuaAura
* *
* @return uint32 stack_amount * @return uint32 stack_amount
*/ */
int GetStackAmount(lua_State* L, Aura* aura) int GetStackAmount(Eluna* E, Aura* aura)
{ {
Eluna::Push(L, aura->GetStackAmount()); Eluna::Push(E->L, aura->GetStackAmount());
return 1; return 1;
} }
@@ -118,12 +118,12 @@ namespace LuaAura
* *
* @return [Unit] owner * @return [Unit] owner
*/ */
int GetOwner(lua_State* L, Aura* aura) int GetOwner(Eluna* E, Aura* aura)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, aura->GetTarget()); Eluna::Push(E->L, aura->GetTarget());
#else #else
Eluna::Push(L, aura->GetOwner()); Eluna::Push(E->L, aura->GetOwner());
#endif #endif
return 1; return 1;
} }
@@ -133,9 +133,9 @@ namespace LuaAura
* *
* @param int32 duration : the new duration of the Aura, in milliseconds * @param int32 duration : the new duration of the Aura, in milliseconds
*/ */
int SetDuration(lua_State* L, Aura* aura) int SetDuration(Eluna* E, Aura* aura)
{ {
int32 duration = Eluna::CHECKVAL<int32>(L, 2); int32 duration = Eluna::CHECKVAL<int32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
aura->GetHolder()->SetAuraDuration(duration); aura->GetHolder()->SetAuraDuration(duration);
#else #else
@@ -152,9 +152,9 @@ namespace LuaAura
* *
* @param int32 duration : the new maximum duration of the Aura, in milliseconds * @param int32 duration : the new maximum duration of the Aura, in milliseconds
*/ */
int SetMaxDuration(lua_State* L, Aura* aura) int SetMaxDuration(Eluna* E, Aura* aura)
{ {
int32 duration = Eluna::CHECKVAL<int32>(L, 2); int32 duration = Eluna::CHECKVAL<int32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
aura->GetHolder()->SetAuraMaxDuration(duration); aura->GetHolder()->SetAuraMaxDuration(duration);
#else #else
@@ -171,9 +171,9 @@ namespace LuaAura
* *
* @param uint32 amount * @param uint32 amount
*/ */
int SetStackAmount(lua_State* L, Aura* aura) int SetStackAmount(Eluna* E, Aura* aura)
{ {
uint8 amount = Eluna::CHECKVAL<uint8>(L, 2); uint8 amount = Eluna::CHECKVAL<uint8>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
aura->GetHolder()->SetStackAmount(amount); aura->GetHolder()->SetStackAmount(amount);
#else #else
@@ -185,13 +185,14 @@ namespace LuaAura
/** /**
* Remove this [Aura] from the [Unit] it is applied to. * Remove this [Aura] from the [Unit] it is applied to.
*/ */
int Remove(lua_State* /*L*/, Aura* aura) int Remove(Eluna* E, Aura* aura)
{ {
#ifndef TRINITY #ifndef TRINITY
aura->GetHolder()->RemoveAura(aura->GetEffIndex()); aura->GetHolder()->RemoveAura(aura->GetEffIndex());
#else #else
aura->Remove(); aura->Remove();
#endif #endif
Eluna::CHECKOBJ<ElunaObject>(E->L, 1)->Invalidate();
return 0; return 0;
} }
}; };

View File

@@ -14,9 +14,9 @@ namespace LuaBattleGround
* *
* @return string name * @return string name
*/ */
int GetName(lua_State* L, BattleGround* bg) int GetName(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetName()); Eluna::Push(E->L, bg->GetName());
return 1; return 1;
} }
@@ -26,11 +26,11 @@ namespace LuaBattleGround
* @param uint32 team : team ID * @param uint32 team : team ID
* @return uint32 count * @return uint32 count
*/ */
int GetAlivePlayersCountByTeam(lua_State* L, BattleGround* bg) int GetAlivePlayersCountByTeam(Eluna* E, BattleGround* bg)
{ {
uint32 team = Eluna::CHECKVAL<uint32>(L, 2); uint32 team = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, bg->GetAlivePlayersCountByTeam((Team)team)); Eluna::Push(E->L, bg->GetAlivePlayersCountByTeam((Team)team));
return 1; return 1;
} }
@@ -39,9 +39,9 @@ namespace LuaBattleGround
* *
* @return [Map] map * @return [Map] map
*/ */
int GetMap(lua_State* L, BattleGround* bg) int GetMap(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetBgMap()); Eluna::Push(E->L, bg->GetBgMap());
return 1; return 1;
} }
@@ -51,11 +51,11 @@ namespace LuaBattleGround
* @param uint32 kills : amount of kills * @param uint32 kills : amount of kills
* @return uint32 bonusHonor * @return uint32 bonusHonor
*/ */
int GetBonusHonorFromKillCount(lua_State* L, BattleGround* bg) int GetBonusHonorFromKillCount(Eluna* E, BattleGround* bg)
{ {
uint32 kills = Eluna::CHECKVAL<uint32>(L, 2); uint32 kills = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, bg->GetBonusHonorFromKill(kills)); Eluna::Push(E->L, bg->GetBonusHonorFromKill(kills));
return 1; return 1;
} }
@@ -64,9 +64,9 @@ namespace LuaBattleGround
* *
* @return BattleGroundBracketId bracketId * @return BattleGroundBracketId bracketId
*/ */
int GetBracketId(lua_State* L, BattleGround* bg) int GetBracketId(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetBracketId()); Eluna::Push(E->L, bg->GetBracketId());
return 1; return 1;
} }
@@ -75,12 +75,12 @@ namespace LuaBattleGround
* *
* @return uint32 endTime * @return uint32 endTime
*/ */
int GetEndTime(lua_State* L, BattleGround* bg) int GetEndTime(Eluna* E, BattleGround* bg)
{ {
#ifdef CATA #ifdef CATA
Eluna::Push(L, bg->GetRemainingTime()); Eluna::Push(E->L, bg->GetRemainingTime());
#else #else
Eluna::Push(L, bg->GetEndTime()); Eluna::Push(E->L, bg->GetEndTime());
#endif #endif
return 1; return 1;
} }
@@ -91,11 +91,11 @@ namespace LuaBattleGround
* @param uint32 team : team ID * @param uint32 team : team ID
* @return uint32 freeSlots * @return uint32 freeSlots
*/ */
int GetFreeSlotsForTeam(lua_State* L, BattleGround* bg) int GetFreeSlotsForTeam(Eluna* E, BattleGround* bg)
{ {
uint32 team = Eluna::CHECKVAL<uint32>(L, 2); uint32 team = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, bg->GetFreeSlotsForTeam((Team)team)); Eluna::Push(E->L, bg->GetFreeSlotsForTeam((Team)team));
return 1; return 1;
} }
@@ -104,9 +104,9 @@ namespace LuaBattleGround
* *
* @return uint32 instanceId * @return uint32 instanceId
*/ */
int GetInstanceId(lua_State* L, BattleGround* bg) int GetInstanceId(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetInstanceID()); Eluna::Push(E->L, bg->GetInstanceID());
return 1; return 1;
} }
@@ -115,9 +115,9 @@ namespace LuaBattleGround
* *
* @return uint32 mapId * @return uint32 mapId
*/ */
int GetMapId(lua_State* L, BattleGround* bg) int GetMapId(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMapId()); Eluna::Push(E->L, bg->GetMapId());
return 1; return 1;
} }
@@ -126,9 +126,9 @@ namespace LuaBattleGround
* *
* @return BattleGroundTypeId typeId * @return BattleGroundTypeId typeId
*/ */
int GetTypeId(lua_State* L, BattleGround* bg) int GetTypeId(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetTypeID()); Eluna::Push(E->L, bg->GetTypeID());
return 1; return 1;
} }
@@ -137,9 +137,9 @@ namespace LuaBattleGround
* *
* @return uint32 maxLevel * @return uint32 maxLevel
*/ */
int GetMaxLevel(lua_State* L, BattleGround* bg) int GetMaxLevel(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMaxLevel()); Eluna::Push(E->L, bg->GetMaxLevel());
return 1; return 1;
} }
@@ -148,9 +148,9 @@ namespace LuaBattleGround
* *
* @return uint32 minLevel * @return uint32 minLevel
*/ */
int GetMinLevel(lua_State* L, BattleGround* bg) int GetMinLevel(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMinLevel()); Eluna::Push(E->L, bg->GetMinLevel());
return 1; return 1;
} }
@@ -159,9 +159,9 @@ namespace LuaBattleGround
* *
* @return uint32 maxPlayerCount * @return uint32 maxPlayerCount
*/ */
int GetMaxPlayers(lua_State* L, BattleGround* bg) int GetMaxPlayers(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMaxPlayers()); Eluna::Push(E->L, bg->GetMaxPlayers());
return 1; return 1;
} }
@@ -170,9 +170,9 @@ namespace LuaBattleGround
* *
* @return uint32 minPlayerCount * @return uint32 minPlayerCount
*/ */
int GetMinPlayers(lua_State* L, BattleGround* bg) int GetMinPlayers(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMinPlayers()); Eluna::Push(E->L, bg->GetMinPlayers());
return 1; return 1;
} }
@@ -181,9 +181,9 @@ namespace LuaBattleGround
* *
* @return uint32 maxTeamPlayerCount * @return uint32 maxTeamPlayerCount
*/ */
int GetMaxPlayersPerTeam(lua_State* L, BattleGround* bg) int GetMaxPlayersPerTeam(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMaxPlayersPerTeam()); Eluna::Push(E->L, bg->GetMaxPlayersPerTeam());
return 1; return 1;
} }
@@ -192,9 +192,9 @@ namespace LuaBattleGround
* *
* @return uint32 minTeamPlayerCount * @return uint32 minTeamPlayerCount
*/ */
int GetMinPlayersPerTeam(lua_State* L, BattleGround* bg) int GetMinPlayersPerTeam(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetMinPlayersPerTeam()); Eluna::Push(E->L, bg->GetMinPlayersPerTeam());
return 1; return 1;
} }
@@ -203,9 +203,9 @@ namespace LuaBattleGround
* *
* @return Team team * @return Team team
*/ */
int GetWinner(lua_State* L, BattleGround* bg) int GetWinner(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetWinner()); Eluna::Push(E->L, bg->GetWinner());
return 1; return 1;
} }
@@ -214,9 +214,9 @@ namespace LuaBattleGround
* *
* @return BattleGroundStatus status * @return BattleGroundStatus status
*/ */
int GetStatus(lua_State* L, BattleGround* bg) int GetStatus(Eluna* E, BattleGround* bg)
{ {
Eluna::Push(L, bg->GetStatus()); Eluna::Push(E->L, bg->GetStatus());
return 1; return 1;
} }
}; };

View File

@@ -14,12 +14,12 @@ namespace LuaCorpse
* *
* @return uint64 ownerGUID * @return uint64 ownerGUID
*/ */
int GetOwnerGUID(lua_State* L, Corpse* corpse) int GetOwnerGUID(Eluna* E, Corpse* corpse)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, corpse->GetOwnerGuid()); Eluna::Push(E->L, corpse->GetOwnerGuid());
#else #else
Eluna::Push(L, corpse->GetOwnerGUID()); Eluna::Push(E->L, corpse->GetOwnerGUID());
#endif #endif
return 1; return 1;
} }
@@ -29,9 +29,9 @@ namespace LuaCorpse
* *
* @return uint32 ghostTime * @return uint32 ghostTime
*/ */
int GetGhostTime(lua_State* L, Corpse* corpse) int GetGhostTime(Eluna* E, Corpse* corpse)
{ {
Eluna::Push(L, uint32(corpse->GetGhostTime())); Eluna::Push(E->L, uint32(corpse->GetGhostTime()));
return 1; return 1;
} }
@@ -49,9 +49,9 @@ namespace LuaCorpse
* *
* @return [CorpseType] corpseType * @return [CorpseType] corpseType
*/ */
int GetType(lua_State* L, Corpse* corpse) int GetType(Eluna* E, Corpse* corpse)
{ {
Eluna::Push(L, corpse->GetType()); Eluna::Push(E->L, corpse->GetType());
return 1; return 1;
} }
@@ -59,7 +59,7 @@ namespace LuaCorpse
* Resets the [Corpse] ghost time. * Resets the [Corpse] ghost time.
* *
*/ */
int ResetGhostTime(lua_State* /*L*/, Corpse* corpse) int ResetGhostTime(Eluna* /*E*/, Corpse* corpse)
{ {
corpse->ResetGhostTime(); corpse->ResetGhostTime();
return 0; return 0;
@@ -69,7 +69,7 @@ namespace LuaCorpse
* Saves the [Corpse] to the database. * Saves the [Corpse] to the database.
* *
*/ */
int SaveToDB(lua_State* /*L*/, Corpse* corpse) int SaveToDB(Eluna* /*E*/, Corpse* corpse)
{ {
corpse->SaveToDB(); corpse->SaveToDB();
return 0; return 0;
@@ -79,7 +79,7 @@ namespace LuaCorpse
* Deletes the [Corpse] from the world. * Deletes the [Corpse] from the world.
* *
*/ */
int DeleteBonesFromWorld(lua_State* /*L*/, Corpse* corpse) int DeleteBonesFromWorld(Eluna* /*E*/, Corpse* corpse)
{ {
corpse->DeleteBonesFromWorld(); corpse->DeleteBonesFromWorld();
return 0; return 0;

View File

@@ -22,9 +22,9 @@ namespace LuaCreature
* *
* @return bool reputationDisabled * @return bool reputationDisabled
*/ */
int IsReputationGainDisabled(lua_State* L, Creature* creature) int IsReputationGainDisabled(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsReputationGainDisabled()); Eluna::Push(E->L, creature->IsReputationGainDisabled());
return 1; return 1;
} }
@@ -34,12 +34,12 @@ namespace LuaCreature
* *
* @return bool regeneratesHealth * @return bool regeneratesHealth
*/ */
int CanRegenerateHealth(lua_State* L, Creature* creature) int CanRegenerateHealth(Eluna* E, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->IsRegeneratingHealth()); Eluna::Push(E->L, creature->IsRegeneratingHealth());
#else #else
Eluna::Push(L, creature->isRegeneratingHealth()); Eluna::Push(E->L, creature->isRegeneratingHealth());
#endif #endif
return 1; return 1;
} }
@@ -51,14 +51,14 @@ namespace LuaCreature
* @param uint32 questID : the ID of a [Quest] * @param uint32 questID : the ID of a [Quest]
* @return bool completesQuest * @return bool completesQuest
*/ */
int CanCompleteQuest(lua_State* L, Creature* creature) int CanCompleteQuest(Eluna* E, Creature* creature)
{ {
uint32 quest_id = Eluna::CHECKVAL<uint32>(L, 2); uint32 quest_id = Eluna::CHECKVAL<uint32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->HasInvolvedQuest(quest_id)); Eluna::Push(E->L, creature->HasInvolvedQuest(quest_id));
#else #else
Eluna::Push(L, creature->hasInvolvedQuest(quest_id)); Eluna::Push(E->L, creature->hasInvolvedQuest(quest_id));
#endif #endif
return 1; return 1;
} }
@@ -70,14 +70,14 @@ namespace LuaCreature
* @param bool mustBeDead = false : if `true`, only returns `true` if the [Creature] is also dead. Otherwise, it must be alive. * @param bool mustBeDead = false : if `true`, only returns `true` if the [Creature] is also dead. Otherwise, it must be alive.
* @return bool targetable * @return bool targetable
*/ */
int IsTargetableForAttack(lua_State* L, Creature* creature) int IsTargetableForAttack(Eluna* E, Creature* creature)
{ {
bool mustBeDead = Eluna::CHECKVAL<bool>(L, 2, false); bool mustBeDead = Eluna::CHECKVAL<bool>(E->L, 2, false);
#ifdef MANGOS #ifdef MANGOS
Eluna::Push(L, creature->IsTargetableForAttack(mustBeDead)); Eluna::Push(E->L, creature->IsTargetableForAttack(mustBeDead));
#else #else
Eluna::Push(L, creature->isTargetableForAttack(mustBeDead)); Eluna::Push(E->L, creature->isTargetableForAttack(mustBeDead));
#endif #endif
return 1; return 1;
} }
@@ -91,13 +91,13 @@ namespace LuaCreature
* @param bool checkFaction = true : if `true`, the [Creature] must be the same faction as `friend` to assist * @param bool checkFaction = true : if `true`, the [Creature] must be the same faction as `friend` to assist
* @return bool canAssist * @return bool canAssist
*/ */
int CanAssistTo(lua_State* L, Creature* creature) int CanAssistTo(Eluna* E, Creature* creature)
{ {
Unit* u = Eluna::CHECKOBJ<Unit>(L, 2); Unit* u = Eluna::CHECKOBJ<Unit>(E->L, 2);
Unit* enemy = Eluna::CHECKOBJ<Unit>(L, 3); Unit* enemy = Eluna::CHECKOBJ<Unit>(E->L, 3);
bool checkfaction = Eluna::CHECKVAL<bool>(L, 4, true); bool checkfaction = Eluna::CHECKVAL<bool>(E->L, 4, true);
Eluna::Push(L, creature->CanAssistTo(u, enemy, checkfaction)); Eluna::Push(E->L, creature->CanAssistTo(u, enemy, checkfaction));
return 1; return 1;
} }
@@ -107,9 +107,9 @@ namespace LuaCreature
* *
* @return bool searchedForAssistance * @return bool searchedForAssistance
*/ */
int HasSearchedAssistance(lua_State* L, Creature* creature) int HasSearchedAssistance(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->HasSearchedAssistance()); Eluna::Push(E->L, creature->HasSearchedAssistance());
return 1; return 1;
} }
@@ -119,14 +119,14 @@ namespace LuaCreature
* *
* @return bool tapped * @return bool tapped
*/ */
int IsTappedBy(lua_State* L, Creature* creature) int IsTappedBy(Eluna* E, Creature* creature)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
#ifdef MANGOS #ifdef MANGOS
Eluna::Push(L, creature->IsTappedBy(player)); Eluna::Push(E->L, creature->IsTappedBy(player));
#else #else
Eluna::Push(L, creature->isTappedBy(player)); Eluna::Push(E->L, creature->isTappedBy(player));
#endif #endif
return 1; return 1;
} }
@@ -137,12 +137,12 @@ namespace LuaCreature
* *
* @return bool hasLootRecipient * @return bool hasLootRecipient
*/ */
int HasLootRecipient(lua_State* L, Creature* creature) int HasLootRecipient(Eluna* E, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->HasLootRecipient()); Eluna::Push(E->L, creature->HasLootRecipient());
#else #else
Eluna::Push(L, creature->hasLootRecipient()); Eluna::Push(E->L, creature->hasLootRecipient());
#endif #endif
return 1; return 1;
} }
@@ -153,13 +153,13 @@ namespace LuaCreature
* *
* @return bool canAggro * @return bool canAggro
*/ */
int CanAggro(lua_State* L, Creature* creature) int CanAggro(Eluna* E, Creature* creature)
{ {
#ifdef TRINITY #ifdef TRINITY
Eluna::Push(L, !creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)); Eluna::Push(E->L, !creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC));
#else #else
// Eluna::Push(L, creature->CanInitiateAttack()); // Eluna::Push(E->L, creature->CanInitiateAttack());
Eluna::Push(L, !creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE)); Eluna::Push(E->L, !creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE));
#endif #endif
return 1; return 1;
} }
@@ -170,9 +170,9 @@ namespace LuaCreature
* *
* @return bool canSwim * @return bool canSwim
*/ */
int CanSwim(lua_State* L, Creature* creature) int CanSwim(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->CanSwim()); Eluna::Push(E->L, creature->CanSwim());
return 1; return 1;
} }
@@ -182,9 +182,9 @@ namespace LuaCreature
* *
* @return bool canWalk * @return bool canWalk
*/ */
int CanWalk(lua_State* L, Creature* creature) int CanWalk(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->CanWalk()); Eluna::Push(E->L, creature->CanWalk());
return 1; return 1;
} }
@@ -194,9 +194,9 @@ namespace LuaCreature
* *
* @return bool inEvadeMode * @return bool inEvadeMode
*/ */
int IsInEvadeMode(lua_State* L, Creature* creature) int IsInEvadeMode(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsInEvadeMode()); Eluna::Push(E->L, creature->IsInEvadeMode());
return 1; return 1;
} }
@@ -206,12 +206,12 @@ namespace LuaCreature
* *
* @return bool isElite * @return bool isElite
*/ */
int IsElite(lua_State* L, Creature* creature) int IsElite(Eluna* E, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->IsElite()); Eluna::Push(E->L, creature->IsElite());
#else #else
Eluna::Push(L, creature->isElite()); Eluna::Push(E->L, creature->isElite());
#endif #endif
return 1; return 1;
} }
@@ -222,9 +222,9 @@ namespace LuaCreature
* *
* @return bool isGuard * @return bool isGuard
*/ */
int IsGuard(lua_State* L, Creature* creature) int IsGuard(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsGuard()); Eluna::Push(E->L, creature->IsGuard());
return 1; return 1;
} }
@@ -234,9 +234,9 @@ namespace LuaCreature
* *
* @return bool isCivilian * @return bool isCivilian
*/ */
int IsCivilian(lua_State* L, Creature* creature) int IsCivilian(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsCivilian()); Eluna::Push(E->L, creature->IsCivilian());
return 1; return 1;
} }
@@ -246,9 +246,9 @@ namespace LuaCreature
* *
* @return bool isLeader * @return bool isLeader
*/ */
int IsRacialLeader(lua_State* L, Creature* creature) int IsRacialLeader(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsRacialLeader()); Eluna::Push(E->L, creature->IsRacialLeader());
return 1; return 1;
} }
@@ -258,12 +258,12 @@ namespace LuaCreature
* *
* @return bool isWorldBoss * @return bool isWorldBoss
*/ */
int IsWorldBoss(lua_State* L, Creature* creature) int IsWorldBoss(Eluna* E, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->IsWorldBoss()); Eluna::Push(E->L, creature->IsWorldBoss());
#else #else
Eluna::Push(L, creature->isWorldBoss()); Eluna::Push(E->L, creature->isWorldBoss());
#endif #endif
return 1; return 1;
} }
@@ -275,11 +275,11 @@ namespace LuaCreature
* @param uint32 spellId : the ID of a [Spell] * @param uint32 spellId : the ID of a [Spell]
* @return bool hasCooldown * @return bool hasCooldown
*/ */
int HasCategoryCooldown(lua_State* L, Creature* creature) int HasCategoryCooldown(Eluna* E, Creature* creature)
{ {
uint32 spell = Eluna::CHECKVAL<uint32>(L, 2); uint32 spell = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, creature->HasCategoryCooldown(spell)); Eluna::Push(E->L, creature->HasCategoryCooldown(spell));
return 1; return 1;
} }
@@ -290,11 +290,11 @@ namespace LuaCreature
* @param uint32 spellId : the ID of a [Spell] * @param uint32 spellId : the ID of a [Spell]
* @return bool hasSpell * @return bool hasSpell
*/ */
int HasSpell(lua_State* L, Creature* creature) int HasSpell(Eluna* E, Creature* creature)
{ {
uint32 id = Eluna::CHECKVAL<uint32>(L, 2); uint32 id = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, creature->HasSpell(id)); Eluna::Push(E->L, creature->HasSpell(id));
return 1; return 1;
} }
@@ -305,14 +305,14 @@ namespace LuaCreature
* @param uint32 questId : the ID of a [Quest] * @param uint32 questId : the ID of a [Quest]
* @return bool hasQuest * @return bool hasQuest
*/ */
int HasQuest(lua_State* L, Creature* creature) int HasQuest(Eluna* E, Creature* creature)
{ {
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2); uint32 questId = Eluna::CHECKVAL<uint32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->HasQuest(questId)); Eluna::Push(E->L, creature->HasQuest(questId));
#else #else
Eluna::Push(L, creature->hasQuest(questId)); Eluna::Push(E->L, creature->hasQuest(questId));
#endif #endif
return 1; return 1;
} }
@@ -324,11 +324,11 @@ namespace LuaCreature
* @param uint32 spellId : the ID of a [Spell] * @param uint32 spellId : the ID of a [Spell]
* @return bool hasCooldown * @return bool hasCooldown
*/ */
int HasSpellCooldown(lua_State* L, Creature* creature) int HasSpellCooldown(Eluna* E, Creature* creature)
{ {
uint32 spellId = Eluna::CHECKVAL<uint32>(L, 2); uint32 spellId = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, creature->HasSpellCooldown(spellId)); Eluna::Push(E->L, creature->HasSpellCooldown(spellId));
return 1; return 1;
} }
@@ -338,9 +338,9 @@ namespace LuaCreature
* *
* @return bool canFly * @return bool canFly
*/ */
int CanFly(lua_State* L, Creature* creature) int CanFly(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->CanFly()); Eluna::Push(E->L, creature->CanFly());
return 1; return 1;
} }
@@ -351,32 +351,32 @@ namespace LuaCreature
* *
* @return bool canFly * @return bool canFly
*/ */
int IsTrigger(lua_State* L, Creature* creature) int IsTrigger(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsTrigger()); Eluna::Push(E->L, creature->IsTrigger());
return 1; return 1;
} }
int IsDamageEnoughForLootingAndReward(lua_State* L, Creature* creature) int IsDamageEnoughForLootingAndReward(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->IsDamageEnoughForLootingAndReward()); Eluna::Push(E->L, creature->IsDamageEnoughForLootingAndReward());
return 1; return 1;
} }
int CanStartAttack(lua_State* L, Creature* creature) // TODO: Implement core side int CanStartAttack(Eluna* E, Creature* creature) // TODO: Implement core side
{ {
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2); Unit* target = Eluna::CHECKOBJ<Unit>(E->L, 2);
bool force = Eluna::CHECKVAL<bool>(L, 3, true); bool force = Eluna::CHECKVAL<bool>(E->L, 3, true);
Eluna::Push(L, creature->CanStartAttack(target, force)); Eluna::Push(E->L, creature->CanStartAttack(target, force));
return 1; return 1;
} }
int HasLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features int HasLootMode(Eluna* E, Creature* creature) // TODO: Implement LootMode features
{ {
uint16 lootMode = Eluna::CHECKVAL<uint16>(L, 2); uint16 lootMode = Eluna::CHECKVAL<uint16>(E->L, 2);
Eluna::Push(L, creature->HasLootMode(lootMode)); Eluna::Push(E->L, creature->HasLootMode(lootMode));
return 1; return 1;
} }
#endif #endif
@@ -391,9 +391,9 @@ namespace LuaCreature
* *
* @return uint32 respawnDelay : the respawn delay, in seconds * @return uint32 respawnDelay : the respawn delay, in seconds
*/ */
int GetRespawnDelay(lua_State* L, Creature* creature) int GetRespawnDelay(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetRespawnDelay()); Eluna::Push(E->L, creature->GetRespawnDelay());
return 1; return 1;
} }
@@ -403,9 +403,9 @@ namespace LuaCreature
* *
* @return float wanderRadius * @return float wanderRadius
*/ */
int GetWanderRadius(lua_State* L, Creature* creature) int GetWanderRadius(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetRespawnRadius()); Eluna::Push(E->L, creature->GetRespawnRadius());
return 1; return 1;
} }
@@ -415,9 +415,9 @@ namespace LuaCreature
* *
* @return uint32 pathId * @return uint32 pathId
*/ */
int GetWaypointPath(lua_State* L, Creature* creature) int GetWaypointPath(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetWaypointPath()); Eluna::Push(E->L, creature->GetWaypointPath());
return 1; return 1;
} }
#endif #endif
@@ -427,12 +427,12 @@ namespace LuaCreature
* *
* @return uint32 wpId * @return uint32 wpId
*/ */
int GetCurrentWaypointId(lua_State* L, Creature* creature) int GetCurrentWaypointId(Eluna* E, Creature* creature)
{ {
#ifdef TRINITY #ifdef TRINITY
Eluna::Push(L, creature->GetCurrentWaypointID()); Eluna::Push(E->L, creature->GetCurrentWaypointID());
#else #else
Eluna::Push(L, creature->GetMotionMaster()->getLastReachedWaypoint()); Eluna::Push(E->L, creature->GetMotionMaster()->getLastReachedWaypoint());
#endif #endif
return 1; return 1;
} }
@@ -442,9 +442,9 @@ namespace LuaCreature
* *
* @return MovementGeneratorType defaultMovementType * @return MovementGeneratorType defaultMovementType
*/ */
int GetDefaultMovementType(lua_State* L, Creature* creature) int GetDefaultMovementType(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetDefaultMovementType()); Eluna::Push(E->L, creature->GetDefaultMovementType());
return 1; return 1;
} }
@@ -454,16 +454,16 @@ namespace LuaCreature
* @param Unit target * @param Unit target
* @return float aggroRange * @return float aggroRange
*/ */
int GetAggroRange(lua_State* L, Creature* creature) int GetAggroRange(Eluna* E, Creature* creature)
{ {
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2); Unit* target = Eluna::CHECKOBJ<Unit>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
float AttackDist = creature->GetAttackDistance(target); float AttackDist = creature->GetAttackDistance(target);
float ThreatRadius = sWorld.getConfig(CONFIG_FLOAT_THREAT_RADIUS); float ThreatRadius = sWorld.getConfig(CONFIG_FLOAT_THREAT_RADIUS);
Eluna::Push(L, ThreatRadius > AttackDist ? ThreatRadius : AttackDist); Eluna::Push(E->L, ThreatRadius > AttackDist ? ThreatRadius : AttackDist);
#else #else
Eluna::Push(L, creature->GetAggroRange(target)); Eluna::Push(E->L, creature->GetAggroRange(target));
#endif #endif
return 1; return 1;
} }
@@ -477,11 +477,11 @@ namespace LuaCreature
* @param Unit target * @param Unit target
* @return float attackDistance * @return float attackDistance
*/ */
int GetAttackDistance(lua_State* L, Creature* creature) int GetAttackDistance(Eluna* E, Creature* creature)
{ {
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2); Unit* target = Eluna::CHECKOBJ<Unit>(E->L, 2);
Eluna::Push(L, creature->GetAttackDistance(target)); Eluna::Push(E->L, creature->GetAttackDistance(target));
return 1; return 1;
} }
@@ -490,12 +490,12 @@ namespace LuaCreature
* *
* @return Group lootRecipientGroup : the group or `nil` * @return Group lootRecipientGroup : the group or `nil`
*/ */
int GetLootRecipientGroup(lua_State* L, Creature* creature) int GetLootRecipientGroup(Eluna* E, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->GetGroupLootRecipient()); Eluna::Push(E->L, creature->GetGroupLootRecipient());
#else #else
Eluna::Push(L, creature->GetLootRecipientGroup()); Eluna::Push(E->L, creature->GetLootRecipientGroup());
#endif #endif
return 1; return 1;
} }
@@ -505,9 +505,9 @@ namespace LuaCreature
* *
* @return Player lootRecipient : the player or `nil` * @return Player lootRecipient : the player or `nil`
*/ */
int GetLootRecipient(lua_State* L, Creature* creature) int GetLootRecipient(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetLootRecipient()); Eluna::Push(E->L, creature->GetLootRecipient());
return 1; return 1;
} }
@@ -520,9 +520,9 @@ namespace LuaCreature
* *
* @return string scriptName * @return string scriptName
*/ */
int GetScriptName(lua_State* L, Creature* creature) int GetScriptName(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetScriptName()); Eluna::Push(E->L, creature->GetScriptName());
return 1; return 1;
} }
@@ -535,9 +535,9 @@ namespace LuaCreature
* *
* @return string AIName * @return string AIName
*/ */
int GetAIName(lua_State* L, Creature* creature) int GetAIName(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetAIName()); Eluna::Push(E->L, creature->GetAIName());
return 1; return 1;
} }
@@ -549,9 +549,9 @@ namespace LuaCreature
* *
* @return uint32 scriptID * @return uint32 scriptID
*/ */
int GetScriptId(lua_State* L, Creature* creature) int GetScriptId(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetScriptId()); Eluna::Push(E->L, creature->GetScriptId());
return 1; return 1;
} }
@@ -561,11 +561,11 @@ namespace LuaCreature
* @param uint32 spellID * @param uint32 spellID
* @return uint32 cooldown : the cooldown, in milliseconds * @return uint32 cooldown : the cooldown, in milliseconds
*/ */
int GetCreatureSpellCooldownDelay(lua_State* L, Creature* creature) int GetCreatureSpellCooldownDelay(Eluna* E, Creature* creature)
{ {
uint32 spell = Eluna::CHECKVAL<uint32>(L, 2); uint32 spell = Eluna::CHECKVAL<uint32>(E->L, 2);
Eluna::Push(L, creature->GetCreatureSpellCooldownDelay(spell)); Eluna::Push(E->L, creature->GetCreatureSpellCooldownDelay(spell));
return 1; return 1;
} }
@@ -574,9 +574,9 @@ namespace LuaCreature
* *
* @return uint32 corpseDelay : the delay, in seconds * @return uint32 corpseDelay : the delay, in seconds
*/ */
int GetCorpseDelay(lua_State* L, Creature* creature) int GetCorpseDelay(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetCorpseDelay()); Eluna::Push(E->L, creature->GetCorpseDelay());
return 1; return 1;
} }
@@ -589,7 +589,7 @@ namespace LuaCreature
* @return float z * @return float z
* @return float o * @return float o
*/ */
int GetHomePosition(lua_State* L, Creature* creature) int GetHomePosition(Eluna* E, Creature* creature)
{ {
float x, y, z, o; float x, y, z, o;
#ifndef TRINITY #ifndef TRINITY
@@ -598,10 +598,10 @@ namespace LuaCreature
creature->GetHomePosition(x, y, z, o); creature->GetHomePosition(x, y, z, o);
#endif #endif
Eluna::Push(L, x); Eluna::Push(E->L, x);
Eluna::Push(L, y); Eluna::Push(E->L, y);
Eluna::Push(L, z); Eluna::Push(E->L, z);
Eluna::Push(L, o); Eluna::Push(E->L, o);
return 4; return 4;
} }
@@ -614,12 +614,12 @@ namespace LuaCreature
* @param float z * @param float z
* @param float o * @param float o
*/ */
int SetHomePosition(lua_State* L, Creature* creature) int SetHomePosition(Eluna* E, Creature* creature)
{ {
float x = Eluna::CHECKVAL<float>(L, 2); float x = Eluna::CHECKVAL<float>(E->L, 2);
float y = Eluna::CHECKVAL<float>(L, 3); float y = Eluna::CHECKVAL<float>(E->L, 3);
float z = Eluna::CHECKVAL<float>(L, 4); float z = Eluna::CHECKVAL<float>(E->L, 4);
float o = Eluna::CHECKVAL<float>(L, 5); float o = Eluna::CHECKVAL<float>(E->L, 5);
#ifndef TRINITY #ifndef TRINITY
creature->SetRespawnCoord(x, y, z, o); creature->SetRespawnCoord(x, y, z, o);
@@ -658,13 +658,13 @@ namespace LuaCreature
* @param int32 aura = 0 : if positive, the target must have this [Aura]. If negative, the the target must not have this Aura * @param int32 aura = 0 : if positive, the target must have this [Aura]. If negative, the the target must not have this Aura
* @return Unit target : the target, or `nil` * @return Unit target : the target, or `nil`
*/ */
int GetAITarget(lua_State* L, Creature* creature) int GetAITarget(Eluna* E, Creature* creature)
{ {
uint32 targetType = Eluna::CHECKVAL<uint32>(L, 2); uint32 targetType = Eluna::CHECKVAL<uint32>(E->L, 2);
bool playerOnly = Eluna::CHECKVAL<bool>(L, 3, false); bool playerOnly = Eluna::CHECKVAL<bool>(E->L, 3, false);
uint32 position = Eluna::CHECKVAL<uint32>(L, 4, 0); uint32 position = Eluna::CHECKVAL<uint32>(E->L, 4, 0);
float dist = Eluna::CHECKVAL<float>(L, 5, 0.0f); float dist = Eluna::CHECKVAL<float>(E->L, 5, 0.0f);
int32 aura = Eluna::CHECKVAL<int32>(L, 6, 0); int32 aura = Eluna::CHECKVAL<int32>(E->L, 6, 0);
#ifdef MANGOS #ifdef MANGOS
ThreatList const& threatlist = creature->GetThreatManager().getThreatList(); ThreatList const& threatlist = creature->GetThreatManager().getThreatList();
@@ -711,7 +711,7 @@ namespace LuaCreature
std::list<Unit*>::const_iterator itr = targetList.begin(); std::list<Unit*>::const_iterator itr = targetList.begin();
if (position) if (position)
std::advance(itr, position); std::advance(itr, position);
Eluna::Push(L, *itr); Eluna::Push(E->L, *itr);
} }
break; break;
case SELECT_TARGET_FARTHEST: case SELECT_TARGET_FARTHEST:
@@ -720,7 +720,7 @@ namespace LuaCreature
std::list<Unit*>::reverse_iterator ritr = targetList.rbegin(); std::list<Unit*>::reverse_iterator ritr = targetList.rbegin();
if (position) if (position)
std::advance(ritr, position); std::advance(ritr, position);
Eluna::Push(L, *ritr); Eluna::Push(E->L, *ritr);
} }
break; break;
case SELECT_TARGET_RANDOM: case SELECT_TARGET_RANDOM:
@@ -730,11 +730,11 @@ namespace LuaCreature
std::advance(itr, urand(0, position)); std::advance(itr, urand(0, position));
else else
std::advance(itr, urand(0, targetList.size() - 1)); std::advance(itr, urand(0, targetList.size() - 1));
Eluna::Push(L, *itr); Eluna::Push(E->L, *itr);
} }
break; break;
default: default:
luaL_argerror(L, 2, "SelectAggroTarget expected"); luaL_argerror(E->L, 2, "SelectAggroTarget expected");
break; break;
} }
@@ -746,10 +746,10 @@ namespace LuaCreature
* *
* @return table targets * @return table targets
*/ */
int GetAITargets(lua_State* L, Creature* creature) int GetAITargets(Eluna* E, Creature* creature)
{ {
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
#ifdef MANGOS #ifdef MANGOS
@@ -765,12 +765,12 @@ namespace LuaCreature
if (!target) if (!target)
continue; continue;
++i; ++i;
Eluna::Push(L, i); Eluna::Push(E->L, i);
Eluna::Push(L, target); Eluna::Push(E->L, target);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); lua_settop(E->L, tbl);
return 1; return 1;
} }
@@ -779,12 +779,12 @@ namespace LuaCreature
* *
* @return int targetsCount * @return int targetsCount
*/ */
int GetAITargetsCount(lua_State* L, Creature* creature) int GetAITargetsCount(Eluna* E, Creature* creature)
{ {
#ifdef MANGOS #ifdef MANGOS
Eluna::Push(L, creature->GetThreatManager().getThreatList().size()); Eluna::Push(E->L, creature->GetThreatManager().getThreatList().size());
#else #else
Eluna::Push(L, creature->getThreatManager().getThreatList().size()); Eluna::Push(E->L, creature->getThreatManager().getThreatList().size());
#endif #endif
return 1; return 1;
} }
@@ -797,9 +797,9 @@ namespace LuaCreature
* *
* @return NPCFlags npcFlags * @return NPCFlags npcFlags
*/ */
int GetNPCFlags(lua_State* L, Creature* creature) int GetNPCFlags(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetUInt32Value(UNIT_NPC_FLAGS)); Eluna::Push(E->L, creature->GetUInt32Value(UNIT_NPC_FLAGS));
return 1; return 1;
} }
@@ -809,17 +809,17 @@ namespace LuaCreature
* *
* @return uint32 shieldBlockValue * @return uint32 shieldBlockValue
*/ */
int GetShieldBlockValue(lua_State* L, Creature* creature) int GetShieldBlockValue(Eluna* E, Creature* creature)
{ {
Eluna::Push(L, creature->GetShieldBlockValue()); Eluna::Push(E->L, creature->GetShieldBlockValue());
return 1; return 1;
} }
#endif #endif
#ifdef TRINITY #ifdef TRINITY
int GetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features int GetLootMode(Eluna* E, Creature* creature) // TODO: Implement LootMode features
{ {
Eluna::Push(L, creature->GetLootMode()); Eluna::Push(E->L, creature->GetLootMode());
return 1; return 1;
} }
#endif #endif
@@ -831,9 +831,9 @@ namespace LuaCreature
* *
* @param NPCFlags flags * @param NPCFlags flags
*/ */
int SetNPCFlags(lua_State* L, Creature* creature) int SetNPCFlags(Eluna* E, Creature* creature)
{ {
uint32 flags = Eluna::CHECKVAL<uint32>(L, 2); uint32 flags = Eluna::CHECKVAL<uint32>(E->L, 2);
creature->SetUInt32Value(UNIT_NPC_FLAGS, flags); creature->SetUInt32Value(UNIT_NPC_FLAGS, flags);
return 0; return 0;
@@ -845,9 +845,9 @@ namespace LuaCreature
* *
* @param bool enable = true * @param bool enable = true
*/ */
int SetDisableGravity(lua_State* L, Creature* creature) int SetDisableGravity(Eluna* E, Creature* creature)
{ {
bool enable = Eluna::CHECKVAL<bool>(L, 2, true); bool enable = Eluna::CHECKVAL<bool>(E->L, 2, true);
#ifdef TRINITY #ifdef TRINITY
creature->SetDisableGravity(!enable); creature->SetDisableGravity(!enable);
@@ -858,9 +858,9 @@ namespace LuaCreature
} }
#ifdef TRINITY #ifdef TRINITY
int SetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features int SetLootMode(Eluna* E, Creature* creature) // TODO: Implement LootMode features
{ {
uint16 lootMode = Eluna::CHECKVAL<uint16>(L, 2); uint16 lootMode = Eluna::CHECKVAL<uint16>(E->L, 2);
creature->SetLootMode(lootMode); creature->SetLootMode(lootMode);
return 0; return 0;
@@ -872,9 +872,9 @@ namespace LuaCreature
* *
* @param DeathState deathState * @param DeathState deathState
*/ */
int SetDeathState(lua_State* L, Creature* creature) int SetDeathState(Eluna* E, Creature* creature)
{ {
int32 state = Eluna::CHECKVAL<int32>(L, 2); int32 state = Eluna::CHECKVAL<int32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
creature->SetDeathState((DeathState)state); creature->SetDeathState((DeathState)state);
@@ -889,9 +889,9 @@ namespace LuaCreature
* *
* @param bool enable = true : `true` to enable walking, `false` for running * @param bool enable = true : `true` to enable walking, `false` for running
*/ */
int SetWalk(lua_State* L, Creature* creature) // TODO: Move same to Player ? int SetWalk(Eluna* E, Creature* creature) // TODO: Move same to Player ?
{ {
bool enable = Eluna::CHECKVAL<bool>(L, 2, true); bool enable = Eluna::CHECKVAL<bool>(E->L, 2, true);
creature->SetWalk(enable); creature->SetWalk(enable);
return 0; return 0;
@@ -904,11 +904,11 @@ namespace LuaCreature
* @param uint32 off_hand : off hand [Item]'s entry * @param uint32 off_hand : off hand [Item]'s entry
* @param uint32 ranged : ranged [Item]'s entry * @param uint32 ranged : ranged [Item]'s entry
*/ */
int SetEquipmentSlots(lua_State* L, Creature* creature) int SetEquipmentSlots(Eluna* E, Creature* creature)
{ {
uint32 main_hand = Eluna::CHECKVAL<uint32>(L, 2); uint32 main_hand = Eluna::CHECKVAL<uint32>(E->L, 2);
uint32 off_hand = Eluna::CHECKVAL<uint32>(L, 3); uint32 off_hand = Eluna::CHECKVAL<uint32>(E->L, 3);
uint32 ranged = Eluna::CHECKVAL<uint32>(L, 4); uint32 ranged = Eluna::CHECKVAL<uint32>(E->L, 4);
#ifdef TRINITY #ifdef TRINITY
creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, main_hand); creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + 0, main_hand);
@@ -927,9 +927,9 @@ namespace LuaCreature
* *
* @param bool allow = true : `true` to allow aggro, `false` to disable aggro * @param bool allow = true : `true` to allow aggro, `false` to disable aggro
*/ */
int SetAggroEnabled(lua_State* L, Creature* creature) int SetAggroEnabled(Eluna* E, Creature* creature)
{ {
bool allow = Eluna::CHECKVAL<bool>(L, 2, true); bool allow = Eluna::CHECKVAL<bool>(E->L, 2, true);
#ifdef TRINITY #ifdef TRINITY
if (allow) if (allow)
@@ -951,9 +951,9 @@ namespace LuaCreature
* *
* @param bool disable = true : `true` to disable reputation, `false` to enable * @param bool disable = true : `true` to disable reputation, `false` to enable
*/ */
int SetDisableReputationGain(lua_State* L, Creature* creature) int SetDisableReputationGain(Eluna* E, Creature* creature)
{ {
bool disable = Eluna::CHECKVAL<bool>(L, 2, true); bool disable = Eluna::CHECKVAL<bool>(E->L, 2, true);
creature->SetDisableReputationGain(disable); creature->SetDisableReputationGain(disable);
return 0; return 0;
@@ -965,7 +965,7 @@ namespace LuaCreature
* This is used by raid bosses to prevent Players from using out-of-combat * This is used by raid bosses to prevent Players from using out-of-combat
* actions once the encounter has begun. * actions once the encounter has begun.
*/ */
int SetInCombatWithZone(lua_State* /*L*/, Creature* creature) int SetInCombatWithZone(Eluna* /*E*/, Creature* creature)
{ {
creature->SetInCombatWithZone(); creature->SetInCombatWithZone();
return 0; return 0;
@@ -976,9 +976,9 @@ namespace LuaCreature
* *
* @param float distance * @param float distance
*/ */
int SetWanderRadius(lua_State* L, Creature* creature) int SetWanderRadius(Eluna* E, Creature* creature)
{ {
float dist = Eluna::CHECKVAL<float>(L, 2); float dist = Eluna::CHECKVAL<float>(E->L, 2);
creature->SetRespawnRadius(dist); creature->SetRespawnRadius(dist);
return 0; return 0;
@@ -989,9 +989,9 @@ namespace LuaCreature
* *
* @param uint32 delay : the delay, in seconds * @param uint32 delay : the delay, in seconds
*/ */
int SetRespawnDelay(lua_State* L, Creature* creature) int SetRespawnDelay(Eluna* E, Creature* creature)
{ {
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2); uint32 delay = Eluna::CHECKVAL<uint32>(E->L, 2);
creature->SetRespawnDelay(delay); creature->SetRespawnDelay(delay);
return 0; return 0;
@@ -1002,9 +1002,9 @@ namespace LuaCreature
* *
* @param MovementGeneratorType type * @param MovementGeneratorType type
*/ */
int SetDefaultMovementType(lua_State* L, Creature* creature) int SetDefaultMovementType(Eluna* E, Creature* creature)
{ {
int32 type = Eluna::CHECKVAL<int32>(L, 2); int32 type = Eluna::CHECKVAL<int32>(E->L, 2);
creature->SetDefaultMovementType((MovementGeneratorType)type); creature->SetDefaultMovementType((MovementGeneratorType)type);
return 0; return 0;
@@ -1015,9 +1015,9 @@ namespace LuaCreature
* *
* @param bool enable = true : `true` to disable searching, `false` to allow * @param bool enable = true : `true` to disable searching, `false` to allow
*/ */
int SetNoSearchAssistance(lua_State* L, Creature* creature) int SetNoSearchAssistance(Eluna* E, Creature* creature)
{ {
bool val = Eluna::CHECKVAL<bool>(L, 2, true); bool val = Eluna::CHECKVAL<bool>(E->L, 2, true);
creature->SetNoSearchAssistance(val); creature->SetNoSearchAssistance(val);
return 0; return 0;
@@ -1028,9 +1028,9 @@ namespace LuaCreature
* *
* @param bool enable = true : `true` to disable calling for help, `false` to enable * @param bool enable = true : `true` to disable calling for help, `false` to enable
*/ */
int SetNoCallAssistance(lua_State* L, Creature* creature) int SetNoCallAssistance(Eluna* E, Creature* creature)
{ {
bool val = Eluna::CHECKVAL<bool>(L, 2, true); bool val = Eluna::CHECKVAL<bool>(E->L, 2, true);
creature->SetNoCallAssistance(val); creature->SetNoCallAssistance(val);
return 0; return 0;
@@ -1041,9 +1041,9 @@ namespace LuaCreature
* *
* @param bool enable = true : `true` to enable hovering, `false` to disable * @param bool enable = true : `true` to enable hovering, `false` to disable
*/ */
int SetHover(lua_State* L, Creature* creature) int SetHover(Eluna* E, Creature* creature)
{ {
bool enable = Eluna::CHECKVAL<bool>(L, 2, true); bool enable = Eluna::CHECKVAL<bool>(E->L, 2, true);
#ifdef TRINITY #ifdef TRINITY
creature->SetHover(enable); creature->SetHover(enable);
@@ -1069,9 +1069,9 @@ namespace LuaCreature
* *
* @param uint32 delay = 0 : dely to despawn in milliseconds * @param uint32 delay = 0 : dely to despawn in milliseconds
*/ */
int DespawnOrUnsummon(lua_State* L, Creature* creature) int DespawnOrUnsummon(Eluna* E, Creature* creature)
{ {
uint32 msTimeToDespawn = Eluna::CHECKVAL<uint32>(L, 2, 0); uint32 msTimeToDespawn = Eluna::CHECKVAL<uint32>(E->L, 2, 0);
#ifndef TRINITY #ifndef TRINITY
creature->ForcedDespawn(msTimeToDespawn); creature->ForcedDespawn(msTimeToDespawn);
@@ -1084,7 +1084,7 @@ namespace LuaCreature
/** /**
* Respawn this [Creature]. * Respawn this [Creature].
*/ */
int Respawn(lua_State* /*L*/, Creature* creature) int Respawn(Eluna* /*E*/, Creature* creature)
{ {
creature->Respawn(); creature->Respawn();
return 0; return 0;
@@ -1093,7 +1093,7 @@ namespace LuaCreature
/** /**
* Remove this [Creature]'s corpse. * Remove this [Creature]'s corpse.
*/ */
int RemoveCorpse(lua_State* /*L*/, Creature* creature) int RemoveCorpse(Eluna* /*E*/, Creature* creature)
{ {
creature->RemoveCorpse(); creature->RemoveCorpse();
return 0; return 0;
@@ -1102,7 +1102,7 @@ namespace LuaCreature
/** /**
* Make the [Creature] start following it's waypoint path. * Make the [Creature] start following it's waypoint path.
*/ */
int MoveWaypoint(lua_State* /*L*/, Creature* creature) int MoveWaypoint(Eluna* /*E*/, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
creature->GetMotionMaster()->MoveWaypoint(); creature->GetMotionMaster()->MoveWaypoint();
@@ -1115,7 +1115,7 @@ namespace LuaCreature
/** /**
* Make the [Creature] call for assistance in combat from other nearby [Creature]s. * Make the [Creature] call for assistance in combat from other nearby [Creature]s.
*/ */
int CallAssistance(lua_State* /*L*/, Creature* creature) int CallAssistance(Eluna* /*E*/, Creature* creature)
{ {
creature->CallAssistance(); creature->CallAssistance();
return 0; return 0;
@@ -1126,9 +1126,9 @@ namespace LuaCreature
* *
* @param float radius * @param float radius
*/ */
int CallForHelp(lua_State* L, Creature* creature) int CallForHelp(Eluna* E, Creature* creature)
{ {
float radius = Eluna::CHECKVAL<float>(L, 2); float radius = Eluna::CHECKVAL<float>(E->L, 2);
creature->CallForHelp(radius); creature->CallForHelp(radius);
return 0; return 0;
@@ -1137,7 +1137,7 @@ namespace LuaCreature
/** /**
* Make the [Creature] flee combat to get assistance from a nearby friendly [Creature]. * Make the [Creature] flee combat to get assistance from a nearby friendly [Creature].
*/ */
int FleeToGetAssistance(lua_State* /*L*/, Creature* creature) int FleeToGetAssistance(Eluna* /*E*/, Creature* creature)
{ {
creature->DoFleeToGetAssistance(); creature->DoFleeToGetAssistance();
return 0; return 0;
@@ -1148,9 +1148,9 @@ namespace LuaCreature
* *
* @param Unit target * @param Unit target
*/ */
int AttackStart(lua_State* L, Creature* creature) int AttackStart(Eluna* E, Creature* creature)
{ {
Unit* target = Eluna::CHECKOBJ<Unit>(L, 2); Unit* target = Eluna::CHECKOBJ<Unit>(E->L, 2);
creature->AI()->AttackStart(target); creature->AI()->AttackStart(target);
return 0; return 0;
@@ -1159,7 +1159,7 @@ namespace LuaCreature
/** /**
* Save the [Creature] in the database. * Save the [Creature] in the database.
*/ */
int SaveToDB(lua_State* /*L*/, Creature* creature) int SaveToDB(Eluna* /*E*/, Creature* creature)
{ {
creature->SaveToDB(); creature->SaveToDB();
return 0; return 0;
@@ -1170,12 +1170,12 @@ namespace LuaCreature
* *
* This should be called every update cycle for the Creature's AI. * This should be called every update cycle for the Creature's AI.
*/ */
int SelectVictim(lua_State* L, Creature* creature) int SelectVictim(Eluna* E, Creature* creature)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, creature->SelectHostileTarget()); Eluna::Push(E->L, creature->SelectHostileTarget());
#else #else
Eluna::Push(L, creature->SelectVictim()); Eluna::Push(E->L, creature->SelectVictim());
#endif #endif
return 1; return 1;
} }
@@ -1186,10 +1186,10 @@ namespace LuaCreature
* @param uint32 entry : the Creature ID to transform into * @param uint32 entry : the Creature ID to transform into
* @param uint32 dataGUIDLow = 0 : use this Creature's model and equipment instead of the defaults * @param uint32 dataGUIDLow = 0 : use this Creature's model and equipment instead of the defaults
*/ */
int UpdateEntry(lua_State* L, Creature* creature) int UpdateEntry(Eluna* E, Creature* creature)
{ {
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 2);
uint32 dataGuidLow = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 dataGuidLow = Eluna::CHECKVAL<uint32>(E->L, 3, 0);
#ifndef TRINITY #ifndef TRINITY
creature->UpdateEntry(entry, ALLIANCE, dataGuidLow ? eObjectMgr->GetCreatureData(dataGuidLow) : NULL); creature->UpdateEntry(entry, ALLIANCE, dataGuidLow ? eObjectMgr->GetCreatureData(dataGuidLow) : NULL);
@@ -1200,23 +1200,23 @@ namespace LuaCreature
} }
#ifdef TRINITY #ifdef TRINITY
int ResetLootMode(lua_State* /*L*/, Creature* creature) // TODO: Implement LootMode features int ResetLootMode(Eluna* /*E*/, Creature* creature) // TODO: Implement LootMode features
{ {
creature->ResetLootMode(); creature->ResetLootMode();
return 0; return 0;
} }
int RemoveLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features int RemoveLootMode(Eluna* E, Creature* creature) // TODO: Implement LootMode features
{ {
uint16 lootMode = Eluna::CHECKVAL<uint16>(L, 2); uint16 lootMode = Eluna::CHECKVAL<uint16>(E->L, 2);
creature->RemoveLootMode(lootMode); creature->RemoveLootMode(lootMode);
return 0; return 0;
} }
int AddLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features int AddLootMode(Eluna* E, Creature* creature) // TODO: Implement LootMode features
{ {
uint16 lootMode = Eluna::CHECKVAL<uint16>(L, 2); uint16 lootMode = Eluna::CHECKVAL<uint16>(E->L, 2);
creature->AddLootMode(lootMode); creature->AddLootMode(lootMode);
return 0; return 0;

View File

@@ -21,40 +21,42 @@ to_Abort(false), events(_events), funcRef(_funcRef), delay(_delay), calls(_calls
LuaEvent::~LuaEvent() LuaEvent::~LuaEvent()
{ {
luaL_unref(sEluna->L, LUA_REGISTRYINDEX, funcRef); // Free lua function ref luaL_unref((*events->E)->L, LUA_REGISTRYINDEX, funcRef); // Free lua function ref
} }
void LuaEvent::Execute() void LuaEvent::Execute()
{ {
// In multithread get map from object and the map's lua state // In multithread get map from object and the map's lua state
lua_rawgeti(sEluna->L, LUA_REGISTRYINDEX, funcRef); lua_rawgeti((*events->E)->L, LUA_REGISTRYINDEX, funcRef);
Eluna::Push(sEluna->L, funcRef); Eluna::Push((*events->E)->L, funcRef);
Eluna::Push(sEluna->L, delay); Eluna::Push((*events->E)->L, delay);
Eluna::Push(sEluna->L, calls); Eluna::Push((*events->E)->L, calls);
if (calls) // Must be before calling if (calls) // Must be before calling
--calls; --calls;
Eluna::Push(sEluna->L, events->obj); Eluna::Push((*events->E)->L, events->obj);
Eluna::ExecuteCall(sEluna->L, 4, 0); (*events->E)->ExecuteCall(4, 0);
ASSERT(!(*events->E)->event_level);
(*events->E)->InvalidateObjects();
} }
ElunaEventProcessor::ElunaEventProcessor(WorldObject* _obj) : m_time(0), obj(_obj) ElunaEventProcessor::ElunaEventProcessor(Eluna** _E, WorldObject* _obj) : m_time(0), obj(_obj), E(_E)
{ {
// In multithread get the object's map's lua state if (obj)
Eluna* E = obj ? sEluna : sEluna; {
EventMgr::WriteGuard lock((*E)->eventMgr->GetLock());
EventMgr::WriteGuard lock(E->eventMgr->GetLock()); (*E)->eventMgr->processors.insert(this);
E->eventMgr->processors.insert(this); }
} }
ElunaEventProcessor::~ElunaEventProcessor() ElunaEventProcessor::~ElunaEventProcessor()
{ {
RemoveEvents(); RemoveEvents();
// In multithread get the object's map's lua state if (obj)
if (Eluna* E = obj ? sEluna : sEluna)
{ {
EventMgr::WriteGuard lock(E->eventMgr->GetLock()); EventMgr::WriteGuard lock((*E)->eventMgr->GetLock());
E->eventMgr->processors.erase(this); (*E)->eventMgr->processors.erase(this);
} }
} }
@@ -117,7 +119,7 @@ void ElunaEventProcessor::AddEvent(int funcRef, uint32 delay, uint32 repeats)
AddEvent(new LuaEvent(this, funcRef, delay, repeats)); AddEvent(new LuaEvent(this, funcRef, delay, repeats));
} }
EventMgr::EventMgr() : globalProcessor(NULL) EventMgr::EventMgr(Eluna** _E) : globalProcessor(new ElunaEventProcessor(_E, NULL)), E(_E)
{ {
} }
@@ -125,6 +127,7 @@ EventMgr::~EventMgr()
{ {
RemoveEvents(); RemoveEvents();
delete globalProcessor; delete globalProcessor;
globalProcessor = NULL;
} }
void EventMgr::RemoveEvents() void EventMgr::RemoveEvents()

View File

@@ -17,6 +17,7 @@
#include "Platform/Define.h" #include "Platform/Define.h"
#endif #endif
class Eluna;
class EventMgr; class EventMgr;
class ElunaEventProcessor; class ElunaEventProcessor;
class WorldObject; class WorldObject;
@@ -49,7 +50,7 @@ public:
typedef std::multimap<uint64, LuaEvent*> EventList; typedef std::multimap<uint64, LuaEvent*> EventList;
typedef UNORDERED_MAP<int, LuaEvent*> EventMap; typedef UNORDERED_MAP<int, LuaEvent*> EventMap;
ElunaEventProcessor(WorldObject* _obj); ElunaEventProcessor(Eluna** _E, WorldObject* _obj);
~ElunaEventProcessor(); ~ElunaEventProcessor();
void Update(uint32 diff); void Update(uint32 diff);
@@ -65,6 +66,7 @@ private:
EventList eventList; EventList eventList;
uint64 m_time; uint64 m_time;
WorldObject* obj; WorldObject* obj;
Eluna** E;
}; };
class EventMgr : public ElunaUtil::RWLockable class EventMgr : public ElunaUtil::RWLockable
@@ -73,8 +75,9 @@ public:
typedef UNORDERED_SET<ElunaEventProcessor*> ProcessorSet; typedef UNORDERED_SET<ElunaEventProcessor*> ProcessorSet;
ProcessorSet processors; ProcessorSet processors;
ElunaEventProcessor* globalProcessor; ElunaEventProcessor* globalProcessor;
Eluna** E;
EventMgr(); EventMgr(Eluna** _E);
~EventMgr(); ~EventMgr();
// Remove all timed events // Remove all timed events

View File

@@ -14,152 +14,152 @@
#endif #endif
namespace LuaQuery namespace LuaQuery
{ {
void CheckFields(lua_State* L, ElunaQuery* result) void CheckFields(Eluna* E, ElunaQuery* result)
{ {
if (Eluna::CHECKVAL<uint32>(L, 2) >= RESULT->GetFieldCount()) if (Eluna::CHECKVAL<uint32>(E->L, 2) >= RESULT->GetFieldCount())
luaL_argerror(L, 2, "invalid field index"); luaL_argerror(E->L, 2, "invalid field index");
} }
/* BOOLEAN */ /* BOOLEAN */
int IsNull(lua_State* L, ElunaQuery* result) int IsNull(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, RESULT->Fetch()[col].IsNULL()); Eluna::Push(E->L, RESULT->Fetch()[col].IsNULL());
#else #else
Eluna::Push(L, RESULT->Fetch()[col].IsNull()); Eluna::Push(E->L, RESULT->Fetch()[col].IsNull());
#endif #endif
return 1; return 1;
} }
/* GETTERS */ /* GETTERS */
int GetColumnCount(lua_State* L, ElunaQuery* result) int GetColumnCount(Eluna* E, ElunaQuery* result)
{ {
Eluna::Push(L, RESULT->GetFieldCount()); Eluna::Push(E->L, RESULT->GetFieldCount());
return 1; return 1;
} }
int GetRowCount(lua_State* L, ElunaQuery* result) int GetRowCount(Eluna* E, ElunaQuery* result)
{ {
if (RESULT->GetRowCount() > (uint32)-1) if (RESULT->GetRowCount() > (uint32)-1)
Eluna::Push(L, (uint32)-1); Eluna::Push(E->L, (uint32)-1);
else else
Eluna::Push(L, RESULT->GetRowCount()); Eluna::Push(E->L, RESULT->GetRowCount());
return 1; return 1;
} }
int GetBool(lua_State* L, ElunaQuery* result) int GetBool(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetBool()); Eluna::Push(E->L, RESULT->Fetch()[col].GetBool());
return 1; return 1;
} }
int GetUInt8(lua_State* L, ElunaQuery* result) int GetUInt8(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt8()); Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt8());
return 1; return 1;
} }
int GetUInt16(lua_State* L, ElunaQuery* result) int GetUInt16(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt16()); Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt16());
return 1; return 1;
} }
int GetUInt32(lua_State* L, ElunaQuery* result) int GetUInt32(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt32()); Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt32());
return 1; return 1;
} }
int GetUInt64(lua_State* L, ElunaQuery* result) int GetUInt64(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetUInt64()); Eluna::Push(E->L, RESULT->Fetch()[col].GetUInt64());
return 1; return 1;
} }
int GetInt8(lua_State* L, ElunaQuery* result) int GetInt8(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt8()); Eluna::Push(E->L, RESULT->Fetch()[col].GetInt8());
return 1; return 1;
} }
int GetInt16(lua_State* L, ElunaQuery* result) int GetInt16(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt16()); Eluna::Push(E->L, RESULT->Fetch()[col].GetInt16());
return 1; return 1;
} }
int GetInt32(lua_State* L, ElunaQuery* result) int GetInt32(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt32()); Eluna::Push(E->L, RESULT->Fetch()[col].GetInt32());
return 1; return 1;
} }
int GetInt64(lua_State* L, ElunaQuery* result) int GetInt64(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetInt64()); Eluna::Push(E->L, RESULT->Fetch()[col].GetInt64());
return 1; return 1;
} }
int GetFloat(lua_State* L, ElunaQuery* result) int GetFloat(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetFloat()); Eluna::Push(E->L, RESULT->Fetch()[col].GetFloat());
return 1; return 1;
} }
int GetDouble(lua_State* L, ElunaQuery* result) int GetDouble(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
Eluna::Push(L, RESULT->Fetch()[col].GetDouble()); Eluna::Push(E->L, RESULT->Fetch()[col].GetDouble());
return 1; return 1;
} }
int GetString(lua_State* L, ElunaQuery* result) int GetString(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, RESULT->Fetch()[col].GetCppString()); Eluna::Push(E->L, RESULT->Fetch()[col].GetCppString());
#else #else
Eluna::Push(L, RESULT->Fetch()[col].GetString()); Eluna::Push(E->L, RESULT->Fetch()[col].GetString());
#endif #endif
return 1; return 1;
} }
int GetCString(lua_State* L, ElunaQuery* result) int GetCString(Eluna* E, ElunaQuery* result)
{ {
uint32 col = Eluna::CHECKVAL<uint32>(L, 2); uint32 col = Eluna::CHECKVAL<uint32>(E->L, 2);
CheckFields(L, result); CheckFields(E, result);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, RESULT->Fetch()[col].GetString()); Eluna::Push(E->L, RESULT->Fetch()[col].GetString());
#else #else
Eluna::Push(L, RESULT->Fetch()[col].GetCString()); Eluna::Push(E->L, RESULT->Fetch()[col].GetCString());
#endif #endif
return 1; return 1;
} }
@@ -172,9 +172,9 @@ namespace LuaQuery
* *
* @return bool hadNextRow * @return bool hadNextRow
*/ */
int NextRow(lua_State* L, ElunaQuery* result) int NextRow(Eluna* E, ElunaQuery* result)
{ {
Eluna::Push(L, RESULT->NextRow()); Eluna::Push(E->L, RESULT->NextRow());
return 1; return 1;
} }
@@ -186,10 +186,10 @@ namespace LuaQuery
* *
* @return table rowData : table filled with row columns and data where `T[column] = data` * @return table rowData : table filled with row columns and data where `T[column] = data`
*/ */
int GetRow(lua_State* L, ElunaQuery* result) int GetRow(Eluna* E, ElunaQuery* result)
{ {
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 col = RESULT->GetFieldCount(); uint32 col = RESULT->GetFieldCount();
Field* row = RESULT->Fetch(); Field* row = RESULT->Fetch();
@@ -201,17 +201,17 @@ namespace LuaQuery
for (uint32 i = 0; i < col; ++i) for (uint32 i = 0; i < col; ++i)
{ {
#ifdef TRINITY #ifdef TRINITY
Eluna::Push(L, RESULT->GetFieldName(i)); Eluna::Push(E->L, RESULT->GetFieldName(i));
const char* str = row[i].GetCString(); const char* str = row[i].GetCString();
if (row[i].IsNull() || !str) if (row[i].IsNull() || !str)
Eluna::Push(L); Eluna::Push(E->L);
#else #else
Eluna::Push(L, names[i]); Eluna::Push(E->L, names[i]);
const char* str = row[i].GetString(); const char* str = row[i].GetString();
if (row[i].IsNULL() || !str) if (row[i].IsNULL() || !str)
Eluna::Push(L); Eluna::Push(E->L);
#endif #endif
else else
{ {
@@ -224,18 +224,18 @@ namespace LuaQuery
case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONG:
case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_DOUBLE: case MYSQL_TYPE_DOUBLE:
Eluna::Push(L, strtod(str, NULL)); Eluna::Push(E->L, strtod(str, NULL));
break; break;
default: default:
Eluna::Push(L, str); Eluna::Push(E->L, str);
break; break;
} }
} }
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); lua_settop(E->L, tbl);
return 1; return 1;
} }
}; };

View File

@@ -16,11 +16,96 @@ extern "C"
#include "LuaEngine.h" #include "LuaEngine.h"
#include "ElunaUtility.h" #include "ElunaUtility.h"
class ElunaGlobal
{
public:
struct ElunaRegister
{
const char* name;
int(*mfunc)(Eluna*);
};
static int thunk(lua_State* L)
{
ElunaRegister* l = static_cast<ElunaRegister*>(lua_touserdata(L, lua_upvalueindex(1)));
Eluna* E = static_cast<Eluna*>(lua_touserdata(L, lua_upvalueindex(2)));
int args = lua_gettop(L);
int expected = l->mfunc(E);
args = lua_gettop(L) - args;
if (args < 0 || args > expected) // Assert instead?
{
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected);
}
for (; args < expected; ++args)
lua_pushnil(L);
return expected;
}
static void SetMethods(Eluna* E, ElunaRegister* methodTable)
{
if (!methodTable)
return;
lua_pushglobaltable(E->L);
for (; methodTable && methodTable->name && methodTable->mfunc; ++methodTable)
{
lua_pushstring(E->L, methodTable->name);
lua_pushlightuserdata(E->L, (void*)methodTable);
lua_pushlightuserdata(E->L, (void*)E);
lua_pushcclosure(E->L, thunk, 2);
lua_settable(E->L, -3);
}
lua_remove(E->L, -1);
}
};
class ElunaObject
{
public:
ElunaObject(void* obj, bool manageMemory) : _isvalid(false), _invalidate(!manageMemory), object(obj)
{
SetValid(true);
}
~ElunaObject()
{
}
void* GetObj() const { return object; }
bool IsValid() const { return _isvalid; }
bool CanInvalidate() const { return _invalidate; }
void SetObj(void* obj)
{
object = obj;
}
void SetValid(bool valid)
{
_isvalid = object && valid;
}
void SetValidation(bool invalidate)
{
_invalidate = invalidate;
}
void Invalidate()
{
if (CanInvalidate())
_isvalid = false;
}
private:
bool _isvalid;
bool _invalidate;
void* object;
};
template<typename T> template<typename T>
struct ElunaRegister struct ElunaRegister
{ {
const char* name; const char* name;
int(*mfunc)(lua_State*, T*); int(*mfunc)(Eluna*, T*);
}; };
template<typename T> template<typename T>
@@ -30,106 +115,88 @@ public:
static const char* tname; static const char* tname;
static bool manageMemory; static bool manageMemory;
static int typeT(lua_State* L)
{
lua_pushstring(L, tname);
return 1;
}
// name will be used as type name // name will be used as type name
// If gc is true, lua will handle the memory management for object pushed // If gc is true, lua will handle the memory management for object pushed
// gc should be used if pushing for example WorldPacket, // gc should be used if pushing for example WorldPacket,
// that will only be needed on lua side and will not be managed by TC/mangos/<core> // that will only be needed on lua side and will not be managed by TC/mangos/<core>
static void Register(lua_State* L, const char* name, bool gc = false) static void Register(Eluna* E, const char* name, bool gc = false)
{ {
ASSERT(!tname || name); ASSERT(!tname || name);
tname = name; tname = name;
manageMemory = gc; manageMemory = gc;
lua_newtable(L); lua_newtable(E->L);
int methods = lua_gettop(L); int methods = lua_gettop(E->L);
// store method table in globals so that // store method table in globals so that
// scripts can add functions in Lua // scripts can add functions in Lua
lua_pushvalue(L, methods); lua_pushvalue(E->L, methods);
lua_setglobal(L, tname); lua_setglobal(E->L, tname);
luaL_newmetatable(L, tname); luaL_newmetatable(E->L, tname);
int metatable = lua_gettop(L); int metatable = lua_gettop(E->L);
// tostring // tostring
lua_pushcfunction(L, tostringT); lua_pushcfunction(E->L, tostringT);
lua_setfield(L, metatable, "__tostring"); lua_setfield(E->L, metatable, "__tostring");
// garbage collecting // garbage collecting
if (manageMemory) if (manageMemory)
{ {
lua_pushcfunction(L, gcT); lua_pushcfunction(E->L, gcT);
lua_setfield(L, metatable, "__gc"); lua_setfield(E->L, metatable, "__gc");
} }
// make methods accessible through metatable // make methods accessible through metatable
lua_pushvalue(L, methods); lua_pushvalue(E->L, methods);
lua_setfield(L, metatable, "__index"); lua_setfield(E->L, metatable, "__index");
// make new indexes saved to methods // make new indexes saved to methods
lua_pushvalue(L, methods); lua_pushvalue(E->L, methods);
lua_setfield(L, metatable, "__newindex"); lua_setfield(E->L, metatable, "__newindex");
// special method to get the object type // special method to get the object type
lua_pushcfunction(L, typeT); lua_pushcfunction(E->L, typeT);
lua_setfield(L, methods, "GetObjectType"); lua_setfield(E->L, methods, "GetObjectType");
// pop methods and metatable // pop methods and metatable
lua_pop(L, 2); lua_pop(E->L, 2);
} }
template<typename C> template<typename C>
static void SetMethods(lua_State* L, ElunaRegister<C>* methodTable) static void SetMethods(Eluna* E, ElunaRegister<C>* methodTable)
{ {
if (!methodTable) if (!methodTable)
return; return;
luaL_getmetatable(L, tname); luaL_getmetatable(E->L, tname);
if (!lua_istable(L, -1)) if (!lua_istable(E->L, -1))
{ {
lua_remove(L, -1); lua_remove(E->L, -1);
ELUNA_LOG_ERROR("%s missing metatable", tname); ELUNA_LOG_ERROR("%s missing metatable", tname);
return; return;
} }
lua_getfield(L, -1, "__index"); lua_getfield(E->L, -1, "__index");
lua_remove(L, -2); lua_remove(E->L, -2);
if (!lua_istable(L, -1)) if (!lua_istable(E->L, -1))
{ {
lua_remove(L, -1); lua_remove(E->L, -1);
ELUNA_LOG_ERROR("%s missing method table from metatable", tname); ELUNA_LOG_ERROR("%s missing method table from metatable", tname);
return; return;
} }
for (; methodTable && methodTable->name && methodTable->mfunc; ++methodTable) for (; methodTable && methodTable->name && methodTable->mfunc; ++methodTable)
{ {
lua_pushstring(L, methodTable->name); lua_pushstring(E->L, methodTable->name);
lua_pushlightuserdata(L, (void*)methodTable); lua_pushlightuserdata(E->L, (void*)methodTable);
lua_pushcclosure(L, thunk, 1); lua_pushlightuserdata(E->L, (void*)E);
lua_settable(L, -3); lua_pushcclosure(E->L, thunk, 2);
lua_settable(E->L, -3);
} }
lua_remove(L, -1); lua_remove(E->L, -1);
}
// Remember special case ElunaTemplate<Vehicle>::gcT
static int gcT(lua_State* L)
{
if (!manageMemory)
return 0;
// Get object pointer (and check type, no error)
T** ptrHold = static_cast<T**>(luaL_testudata(L, -1, tname));
if (ptrHold)
delete *ptrHold;
return 0;
} }
static int push(lua_State* L, T const* obj) static int push(lua_State* L, T const* obj)
@@ -140,91 +207,125 @@ public:
return 1; return 1;
} }
if (!manageMemory) //if (!manageMemory)
{ //{
lua_rawgeti(L, LUA_REGISTRYINDEX, sEluna->userdata_table); lua_getglobal(L, ELUNA_OBJECT_STORE);
ASSERT(lua_istable(L, -1));
lua_pushfstring(L, "%p", obj); lua_pushfstring(L, "%p", obj);
lua_gettable(L, -2); lua_gettable(L, -2);
if (!lua_isnoneornil(L, -1) && luaL_checkudata(L, -1, tname)) if (!lua_isnoneornil(L, -1) && luaL_checkudata(L, -1, tname))
{ {
// remove userdata_table, leave userdata
lua_remove(L, -2); lua_remove(L, -2);
// set userdata valid
if (ElunaObject* elunaObj = Eluna::CHECKOBJ<ElunaObject>(L, -1, false))
elunaObj->SetValid(true);
return 1; return 1;
} }
lua_remove(L, -1); lua_remove(L, -1);
// left userdata_table in stack // left userdata_table in stack
} //}
// Create new userdata // Create new userdata
T const** ptrHold = static_cast<T const**>(lua_newuserdata(L, sizeof(T const*))); ElunaObject** ptrHold = static_cast<ElunaObject**>(lua_newuserdata(L, sizeof(ElunaObject*)));
if (!ptrHold) if (!ptrHold)
{ {
ELUNA_LOG_ERROR("%s could not create new userdata", tname); ELUNA_LOG_ERROR("%s could not create new userdata", tname);
lua_pop(L, manageMemory ? 1 : 2); lua_pop(L, 2 /*manageMemory ? 1 : 2*/);
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
} }
*ptrHold = obj; *ptrHold = new ElunaObject((void*)(obj), manageMemory);
// Set metatable for it // Set metatable for it
luaL_getmetatable(L, tname); luaL_getmetatable(L, tname);
if (!lua_istable(L, -1)) if (!lua_istable(L, -1))
{ {
ELUNA_LOG_ERROR("%s missing metatable", tname); ELUNA_LOG_ERROR("%s missing metatable", tname);
lua_pop(L, manageMemory ? 2 : 3); lua_pop(L, 3 /*manageMemory ? 2 : 3*/);
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
} }
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
if (!manageMemory) //if (!manageMemory)
{ //{
lua_pushfstring(L, "%p", obj); lua_pushfstring(L, "%p", obj);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_settable(L, -4); lua_settable(L, -4);
lua_remove(L, -2); lua_remove(L, -2);
} //}
return 1; return 1;
} }
static T* check(lua_State* L, int narg, bool error = true) static T* check(lua_State* L, int narg, bool error = true)
{ {
T** ptrHold = static_cast<T**>(lua_touserdata(L, narg)); ElunaObject* elunaObj = Eluna::CHECKOBJ<ElunaObject>(L, narg, error);
if (!ptrHold)
if (!elunaObj)
return NULL;
//if (!manageMemory)
//{
// // Check pointer validity
// lua_rawgeti(L, LUA_REGISTRYINDEX, sEluna->userdata_table);
// lua_pushfstring(L, "%p", (*ptrHold)->GetObj());
// lua_gettable(L, -2);
// lua_remove(L, -2);
// bool valid = lua_isuserdata(L, -1) != 0;
// lua_remove(L, -1);
// if (!valid)
// {
// char buff[256];
// snprintf(buff, 256, "%s expected, got pointer to nonexisting object (%s). This should never happen", tname, luaL_typename(L, narg));
// if (error)
// {
// luaL_argerror(L, narg, buff);
// }
// else
// {
// ELUNA_LOG_ERROR("%s", buff);
// }
// return NULL;
// }
//}
if (!elunaObj->IsValid())
{ {
char buff[256];
snprintf(buff, 256, "%s expected, got pointer to nonexisting (invalidated) object (%s). Check your code.", tname, luaL_typename(L, narg));
if (error) if (error)
{ {
char buff[256];
snprintf(buff, 256, "%s expected, got %s", tname, luaL_typename(L, narg));
luaL_argerror(L, narg, buff); luaL_argerror(L, narg, buff);
} }
else
{
ELUNA_LOG_ERROR("%s", buff);
}
return NULL; return NULL;
} }
return static_cast<T*>(elunaObj->GetObj());
}
if (!manageMemory) static int typeT(lua_State* L)
{
lua_pushstring(L, tname);
return 1;
}
// Remember special case ElunaTemplate<Vehicle>::gcT
static int gcT(lua_State* L)
{
// Get object pointer (and check type, no error)
ElunaObject** ptrHold = static_cast<ElunaObject**>(luaL_testudata(L, -1, tname));
if (ptrHold)
{ {
// Check pointer validity if (manageMemory)
lua_rawgeti(L, LUA_REGISTRYINDEX, sEluna->userdata_table); delete static_cast<T*>((*ptrHold)->GetObj());
lua_pushfstring(L, "%p", *ptrHold); delete *ptrHold;
lua_gettable(L, -2);
lua_remove(L, -2);
bool valid = lua_isuserdata(L, -1) != 0;
lua_remove(L, -1);
if (!valid)
{
char buff[256];
snprintf(buff, 256, "%s expected, got pointer to nonexisting object (%s). This should never happen", tname, luaL_typename(L, narg));
if (error)
{
luaL_argerror(L, narg, buff);
}
else
{
ELUNA_LOG_ERROR("%s", buff);
}
return NULL;
}
} }
return *ptrHold; return 0;
} }
static int thunk(lua_State* L) static int thunk(lua_State* L)
@@ -233,16 +334,18 @@ public:
if (!obj) if (!obj)
return 0; return 0;
ElunaRegister<T>* l = static_cast<ElunaRegister<T>*>(lua_touserdata(L, lua_upvalueindex(1))); ElunaRegister<T>* l = static_cast<ElunaRegister<T>*>(lua_touserdata(L, lua_upvalueindex(1)));
int args = lua_gettop(L); Eluna* E = static_cast<Eluna*>(lua_touserdata(L, lua_upvalueindex(2)));
int expected = l->mfunc(L, obj); int top = lua_gettop(L);
args = lua_gettop(L) - args; int expected = l->mfunc(E, obj);
int args = lua_gettop(L) - top;
if (args < 0 || args > expected) // Assert instead? if (args < 0 || args > expected) // Assert instead?
{ {
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected); ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected);
} }
for (; args < expected; ++args) if (args == expected)
lua_pushnil(L); return expected;
return expected; lua_settop(L, top);
return 0;
} }
static int tostringT(lua_State* L) static int tostringT(lua_State* L)

View File

@@ -15,14 +15,14 @@ namespace LuaGameObject
* @param uint32 questId : quest entry Id to check * @param uint32 questId : quest entry Id to check
* @return bool hasQuest * @return bool hasQuest
*/ */
int HasQuest(lua_State* L, GameObject* go) int HasQuest(Eluna* E, GameObject* go)
{ {
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2); uint32 questId = Eluna::CHECKVAL<uint32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, go->HasQuest(questId)); Eluna::Push(E->L, go->HasQuest(questId));
#else #else
Eluna::Push(L, go->hasQuest(questId)); Eluna::Push(E->L, go->hasQuest(questId));
#endif #endif
return 1; return 1;
} }
@@ -32,9 +32,9 @@ namespace LuaGameObject
* *
* @return bool isSpawned * @return bool isSpawned
*/ */
int IsSpawned(lua_State* L, GameObject* go) int IsSpawned(Eluna* E, GameObject* go)
{ {
Eluna::Push(L, go->isSpawned()); Eluna::Push(E->L, go->isSpawned());
return 1; return 1;
} }
@@ -43,9 +43,9 @@ namespace LuaGameObject
* *
* @return bool isTransport * @return bool isTransport
*/ */
int IsTransport(lua_State* L, GameObject* go) int IsTransport(Eluna* E, GameObject* go)
{ {
Eluna::Push(L, go->IsTransport()); Eluna::Push(E->L, go->IsTransport());
return 1; return 1;
} }
@@ -54,15 +54,15 @@ namespace LuaGameObject
* *
* @return bool isActive * @return bool isActive
*/ */
int IsActive(lua_State* L, GameObject* go) int IsActive(Eluna* E, GameObject* go)
{ {
Eluna::Push(L, go->isActiveObject()); Eluna::Push(E->L, go->isActiveObject());
return 1; return 1;
} }
/*int IsDestructible(lua_State* L, GameObject* go) // TODO: Implementation core side /*int IsDestructible(Eluna* E, GameObject* go) // TODO: Implementation core side
{ {
Eluna::Push(L, go->IsDestructibleBuilding()); Eluna::Push(E->L, go->IsDestructibleBuilding());
return 1; return 1;
}*/ }*/
@@ -71,9 +71,9 @@ namespace LuaGameObject
* *
* @return uint32 displayId * @return uint32 displayId
*/ */
int GetDisplayId(lua_State* L, GameObject* go) int GetDisplayId(Eluna* E, GameObject* go)
{ {
Eluna::Push(L, go->GetDisplayId()); Eluna::Push(E->L, go->GetDisplayId());
return 1; return 1;
} }
@@ -92,9 +92,9 @@ namespace LuaGameObject
* *
* @return [GOState] goState * @return [GOState] goState
*/ */
int GetGoState(lua_State* L, GameObject* go) int GetGoState(Eluna* E, GameObject* go)
{ {
Eluna::Push(L, go->GetGoState()); Eluna::Push(E->L, go->GetGoState());
return 1; return 1;
} }
@@ -114,9 +114,9 @@ namespace LuaGameObject
* *
* @return [LootState] lootState * @return [LootState] lootState
*/ */
int GetLootState(lua_State* L, GameObject* go) int GetLootState(Eluna* E, GameObject* go)
{ {
Eluna::Push(L, go->getLootState()); Eluna::Push(E->L, go->getLootState());
return 1; return 1;
} }
@@ -134,9 +134,9 @@ namespace LuaGameObject
* *
* @param [GOState] state : all available go states can be seen above * @param [GOState] state : all available go states can be seen above
*/ */
int SetGoState(lua_State* L, GameObject* go) int SetGoState(Eluna* E, GameObject* go)
{ {
uint32 state = Eluna::CHECKVAL<uint32>(L, 2, 0); uint32 state = Eluna::CHECKVAL<uint32>(E->L, 2, 0);
if (state == 0) if (state == 0)
go->SetGoState(GO_STATE_ACTIVE); go->SetGoState(GO_STATE_ACTIVE);
@@ -164,9 +164,9 @@ namespace LuaGameObject
* *
* @param [LootState] state : all available loot states can be seen above * @param [LootState] state : all available loot states can be seen above
*/ */
int SetLootState(lua_State* L, GameObject* go) int SetLootState(Eluna* E, GameObject* go)
{ {
uint32 state = Eluna::CHECKVAL<uint32>(L, 2, 0); uint32 state = Eluna::CHECKVAL<uint32>(E->L, 2, 0);
if (state == 0) if (state == 0)
go->SetLootState(GO_NOT_READY); go->SetLootState(GO_NOT_READY);
@@ -184,7 +184,7 @@ namespace LuaGameObject
* Saves [GameObject] to the database * Saves [GameObject] to the database
* *
*/ */
int SaveToDB(lua_State* /*L*/, GameObject* go) int SaveToDB(Eluna* /*E*/, GameObject* go)
{ {
go->SaveToDB(); go->SaveToDB();
return 0; return 0;
@@ -195,9 +195,9 @@ namespace LuaGameObject
* *
* @param bool deleteFromDB : if true, it will delete the [GameObject] from the database * @param bool deleteFromDB : if true, it will delete the [GameObject] from the database
*/ */
int RemoveFromWorld(lua_State* L, GameObject* go) int RemoveFromWorld(Eluna* E, GameObject* go)
{ {
bool deldb = Eluna::CHECKVAL<bool>(L, 2, false); bool deldb = Eluna::CHECKVAL<bool>(E->L, 2, false);
if (deldb) if (deldb)
go->DeleteFromDB(); go->DeleteFromDB();
go->RemoveFromWorld(); go->RemoveFromWorld();
@@ -209,9 +209,9 @@ namespace LuaGameObject
* *
* @param uint32 delay : cooldown time in seconds to restore the [GameObject] back to normal * @param uint32 delay : cooldown time in seconds to restore the [GameObject] back to normal
*/ */
int UseDoorOrButton(lua_State* L, GameObject* go) int UseDoorOrButton(Eluna* E, GameObject* go)
{ {
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 0); uint32 delay = Eluna::CHECKVAL<uint32>(E->L, 2, 0);
go->UseDoorOrButton(delay); go->UseDoorOrButton(delay);
return 0; return 0;
@@ -222,9 +222,9 @@ namespace LuaGameObject
* *
* @param uint32 delay : time in seconds to despawn * @param uint32 delay : time in seconds to despawn
*/ */
int Despawn(lua_State* L, GameObject* go) int Despawn(Eluna* E, GameObject* go)
{ {
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 1); uint32 delay = Eluna::CHECKVAL<uint32>(E->L, 2, 1);
if (!delay) if (!delay)
delay = 1; delay = 1;
@@ -238,9 +238,9 @@ namespace LuaGameObject
* *
* @param uint32 delay : time of respawn in seconds * @param uint32 delay : time of respawn in seconds
*/ */
int Respawn(lua_State* L, GameObject* go) int Respawn(Eluna* E, GameObject* go)
{ {
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 1); uint32 delay = Eluna::CHECKVAL<uint32>(E->L, 2, 1);
if (!delay) if (!delay)
delay = 1; delay = 1;

File diff suppressed because it is too large Load Diff

View File

@@ -15,10 +15,10 @@ namespace LuaGroup
* @param uint64 guid : guid of a possible leader * @param uint64 guid : guid of a possible leader
* @return bool isLeader * @return bool isLeader
*/ */
int IsLeader(lua_State* L, Group* group) int IsLeader(Eluna* E, Group* group)
{ {
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2); uint64 guid = Eluna::CHECKVAL<uint64>(E->L, 2);
Eluna::Push(L, group->IsLeader(ObjectGuid(guid))); Eluna::Push(E->L, group->IsLeader(ObjectGuid(guid)));
return 1; return 1;
} }
@@ -27,9 +27,9 @@ namespace LuaGroup
* *
* @return bool isFull * @return bool isFull
*/ */
int IsFull(lua_State* L, Group* group) int IsFull(Eluna* E, Group* group)
{ {
Eluna::Push(L, group->IsFull()); Eluna::Push(E->L, group->IsFull());
return 1; return 1;
} }
@@ -38,9 +38,9 @@ namespace LuaGroup
* *
* @return bool isRaid * @return bool isRaid
*/ */
int IsRaidGroup(lua_State* L, Group* group) int IsRaidGroup(Eluna* E, Group* group)
{ {
Eluna::Push(L, group->isRaidGroup()); Eluna::Push(E->L, group->isRaidGroup());
return 1; return 1;
} }
@@ -49,9 +49,9 @@ namespace LuaGroup
* *
* @return bool isBG * @return bool isBG
*/ */
int IsBGGroup(lua_State* L, Group* group) int IsBGGroup(Eluna* E, Group* group)
{ {
Eluna::Push(L, group->isBGGroup()); Eluna::Push(E->L, group->isBGGroup());
return 1; return 1;
} }
@@ -61,10 +61,10 @@ namespace LuaGroup
* @param [Player] player : [Player] to check * @param [Player] player : [Player] to check
* @return bool isMember * @return bool isMember
*/ */
int IsMember(lua_State* L, Group* group) int IsMember(Eluna* E, Group* group)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
Eluna::Push(L, group->IsMember(player->GET_GUID())); Eluna::Push(E->L, group->IsMember(player->GET_GUID()));
return 1; return 1;
} }
@@ -74,11 +74,11 @@ namespace LuaGroup
* @param [Player] player : [Player] to check * @param [Player] player : [Player] to check
* @return bool isAssistant * @return bool isAssistant
*/ */
int IsAssistant(lua_State* L, Group* group) int IsAssistant(Eluna* E, Group* group)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
Eluna::Push(L, group->IsAssistant(player->GET_GUID())); Eluna::Push(E->L, group->IsAssistant(player->GET_GUID()));
return 1; return 1;
} }
@@ -89,11 +89,11 @@ namespace LuaGroup
* @param [Player] player2 : second [Player] to check * @param [Player] player2 : second [Player] to check
* @return bool sameSubGroup * @return bool sameSubGroup
*/ */
int SameSubGroup(lua_State* L, Group* group) int SameSubGroup(Eluna* E, Group* group)
{ {
Player* player1 = Eluna::CHECKOBJ<Player>(L, 2); Player* player1 = Eluna::CHECKOBJ<Player>(E->L, 2);
Player* player2 = Eluna::CHECKOBJ<Player>(L, 3); Player* player2 = Eluna::CHECKOBJ<Player>(E->L, 3);
Eluna::Push(L, group->SameSubGroup(player1, player2)); Eluna::Push(E->L, group->SameSubGroup(player1, player2));
return 1; return 1;
} }
@@ -103,10 +103,10 @@ namespace LuaGroup
* @param uint8 subGroup : subGroup ID to check * @param uint8 subGroup : subGroup ID to check
* @return bool hasFreeSlot * @return bool hasFreeSlot
*/ */
int HasFreeSlotSubGroup(lua_State* L, Group* group) int HasFreeSlotSubGroup(Eluna* E, Group* group)
{ {
uint8 subGroup = Eluna::CHECKVAL<uint8>(L, 2); uint8 subGroup = Eluna::CHECKVAL<uint8>(E->L, 2);
Eluna::Push(L, group->HasFreeSlotSubGroup(subGroup)); Eluna::Push(E->L, group->HasFreeSlotSubGroup(subGroup));
return 1; return 1;
} }
@@ -116,23 +116,23 @@ namespace LuaGroup
* @param [Player] player : [Player] to invite * @param [Player] player : [Player] to invite
* @return bool invited * @return bool invited
*/ */
int AddInvite(lua_State* L, Group* group) int AddInvite(Eluna* E, Group* group)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
Eluna::Push(L, group->AddInvite(player)); Eluna::Push(E->L, group->AddInvite(player));
return 1; return 1;
} }
/*int IsLFGGroup(lua_State* L, Group* group) // TODO: Implementation /*int IsLFGGroup(Eluna* E, Group* group) // TODO: Implementation
{ {
Eluna::Push(L, group->isLFGGroup()); Eluna::Push(E->L, group->isLFGGroup());
return 1; return 1;
}*/ }*/
/*int IsBFGroup(lua_State* L, Group* group) // TODO: Implementation /*int IsBFGroup(Eluna* E, Group* group) // TODO: Implementation
{ {
Eluna::Push(L, group->isBFGroup()); Eluna::Push(E->L, group->isBFGroup());
return 1; return 1;
}*/ }*/
@@ -141,10 +141,10 @@ namespace LuaGroup
* *
* @return table groupPlayers : table of [Player]s * @return table groupPlayers : table of [Player]s
*/ */
int GetMembers(lua_State* L, Group* group) int GetMembers(Eluna* E, Group* group)
{ {
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
for (GroupReference* itr = group->GetFirstMember(); itr; itr = itr->next()) for (GroupReference* itr = group->GetFirstMember(); itr; itr = itr->next())
@@ -159,12 +159,12 @@ namespace LuaGroup
continue; continue;
++i; ++i;
Eluna::Push(L, i); Eluna::Push(E->L, i);
Eluna::Push(L, member); Eluna::Push(E->L, member);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); // push table to top of stack lua_settop(E->L, tbl); // push table to top of stack
return 1; return 1;
} }
@@ -173,12 +173,12 @@ namespace LuaGroup
* *
* @return uint64 leaderGUID * @return uint64 leaderGUID
*/ */
int GetLeaderGUID(lua_State* L, Group* group) int GetLeaderGUID(Eluna* E, Group* group)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, group->GetLeaderGuid()); Eluna::Push(E->L, group->GetLeaderGuid());
#else #else
Eluna::Push(L, group->GetLeaderGUID()); Eluna::Push(E->L, group->GetLeaderGUID());
#endif #endif
return 1; return 1;
} }
@@ -188,12 +188,12 @@ namespace LuaGroup
* *
* @return [Player] leader * @return [Player] leader
*/ */
int GetLeader(lua_State* L, Group* group) int GetLeader(Eluna* E, Group* group)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, eObjectAccessor->FindPlayer(group->GetLeaderGuid())); Eluna::Push(E->L, eObjectAccessor->FindPlayer(group->GetLeaderGuid()));
#else #else
Eluna::Push(L, eObjectAccessor->FindPlayer(group->GetLeaderGUID())); Eluna::Push(E->L, eObjectAccessor->FindPlayer(group->GetLeaderGUID()));
#endif #endif
return 1; return 1;
} }
@@ -203,12 +203,12 @@ namespace LuaGroup
* *
* @return uint64 groupGUID * @return uint64 groupGUID
*/ */
int GetGUID(lua_State* L, Group* group) int GetGUID(Eluna* E, Group* group)
{ {
#ifdef CLASSIC #ifdef CLASSIC
Eluna::Push(L, group->GetId()); Eluna::Push(E->L, group->GetId());
#else #else
Eluna::Push(L, group->GET_GUID()); Eluna::Push(E->L, group->GET_GUID());
#endif #endif
return 1; return 1;
} }
@@ -219,13 +219,13 @@ namespace LuaGroup
* @param string name : the [Player]'s name * @param string name : the [Player]'s name
* @return uint64 memberGUID * @return uint64 memberGUID
*/ */
int GetMemberGUID(lua_State* L, Group* group) int GetMemberGUID(Eluna* E, Group* group)
{ {
const char* name = Eluna::CHECKVAL<const char*>(L, 2); const char* name = Eluna::CHECKVAL<const char*>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, group->GetMemberGuid(name)); Eluna::Push(E->L, group->GetMemberGuid(name));
#else #else
Eluna::Push(L, group->GetMemberGUID(name)); Eluna::Push(E->L, group->GetMemberGUID(name));
#endif #endif
return 1; return 1;
} }
@@ -235,9 +235,9 @@ namespace LuaGroup
* *
* @return uint32 memberCount * @return uint32 memberCount
*/ */
int GetMembersCount(lua_State* L, Group* group) int GetMembersCount(Eluna* E, Group* group)
{ {
Eluna::Push(L, group->GetMembersCount()); Eluna::Push(E->L, group->GetMembersCount());
return 1; return 1;
} }
@@ -247,11 +247,11 @@ namespace LuaGroup
* @param [Player] player : the [Player] to check * @param [Player] player : the [Player] to check
* @return uint8 subGroupID * @return uint8 subGroupID
*/ */
int GetMemberGroup(lua_State* L, Group* group) int GetMemberGroup(Eluna* E, Group* group)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
Eluna::Push(L, group->GetMemberGroup(player->GET_GUID())); Eluna::Push(E->L, group->GetMemberGroup(player->GET_GUID()));
return 1; return 1;
} }
@@ -260,9 +260,9 @@ namespace LuaGroup
* *
* @param [Player] leader : the [Player] leader to change * @param [Player] leader : the [Player] leader to change
*/ */
int SetLeader(lua_State* L, Group* group) int SetLeader(Eluna* E, Group* group)
{ {
Player* leader = Eluna::CHECKOBJ<Player>(L, 2); Player* leader = Eluna::CHECKOBJ<Player>(E->L, 2);
group->ChangeLeader(leader->GET_GUID()); group->ChangeLeader(leader->GET_GUID());
return 0; return 0;
@@ -275,11 +275,11 @@ namespace LuaGroup
* @param bool ignorePlayersInBg : ignores [Player]s in a battleground * @param bool ignorePlayersInBg : ignores [Player]s in a battleground
* @param uint64 ignore : ignore a [Player] by their GUID * @param uint64 ignore : ignore a [Player] by their GUID
*/ */
int SendPacket(lua_State* L, Group* group) int SendPacket(Eluna* E, Group* group)
{ {
WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(L, 2); WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(E->L, 2);
bool ignorePlayersInBg = Eluna::CHECKVAL<bool>(L, 3); bool ignorePlayersInBg = Eluna::CHECKVAL<bool>(E->L, 3);
uint64 ignore = Eluna::CHECKVAL<uint64>(L, 4); uint64 ignore = Eluna::CHECKVAL<uint64>(E->L, 4);
group->BroadcastPacket(data, ignorePlayersInBg, -1, ObjectGuid(ignore)); group->BroadcastPacket(data, ignorePlayersInBg, -1, ObjectGuid(ignore));
return 0; return 0;
@@ -302,15 +302,15 @@ namespace LuaGroup
* @param [RemoveMethod] method : method used to remove the player * @param [RemoveMethod] method : method used to remove the player
* @return bool removed * @return bool removed
*/ */
int RemoveMember(lua_State* L, Group* group) int RemoveMember(Eluna* E, Group* group)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
uint32 method = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 method = Eluna::CHECKVAL<uint32>(E->L, 3, 0);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, group->RemoveMember(player->GET_GUID(), method)); Eluna::Push(E->L, group->RemoveMember(player->GET_GUID(), method));
#else #else
Eluna::Push(L, group->RemoveMember(player->GET_GUID(), (RemoveMethod)method)); Eluna::Push(E->L, group->RemoveMember(player->GET_GUID(), (RemoveMethod)method));
#endif #endif
return 1; return 1;
} }
@@ -319,7 +319,7 @@ namespace LuaGroup
* Disbands this [Group] * Disbands this [Group]
* *
*/ */
int Disband(lua_State* /*L*/, Group* group) int Disband(Eluna* /*E*/, Group* group)
{ {
group->Disband(); group->Disband();
return 0; return 0;
@@ -329,7 +329,7 @@ namespace LuaGroup
* Converts this [Group] to a raid [Group] * Converts this [Group] to a raid [Group]
* *
*/ */
int ConvertToRaid(lua_State* /*L*/, Group* group) int ConvertToRaid(Eluna* /*E*/, Group* group)
{ {
group->ConvertToRaid(); group->ConvertToRaid();
return 0; return 0;
@@ -341,10 +341,10 @@ namespace LuaGroup
* @param [Player] player : [Player] to move * @param [Player] player : [Player] to move
* @param uint8 groupID : the subGroup's ID * @param uint8 groupID : the subGroup's ID
*/ */
int SetMembersGroup(lua_State* L, Group* group) int SetMembersGroup(Eluna* E, Group* group)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
uint8 groupID = Eluna::CHECKVAL<uint8>(L, 3); uint8 groupID = Eluna::CHECKVAL<uint8>(E->L, 3);
group->ChangeMembersGroup(player->GET_GUID(), groupID); group->ChangeMembersGroup(player->GET_GUID(), groupID);
return 0; return 0;
@@ -357,14 +357,14 @@ namespace LuaGroup
* @param uint64 target : GUID of the icon target, 0 is to clear the icon * @param uint64 target : GUID of the icon target, 0 is to clear the icon
* @param uint64 setter : GUID of the icon setter * @param uint64 setter : GUID of the icon setter
*/ */
int SetTargetIcon(lua_State* L, Group* group) int SetTargetIcon(Eluna* E, Group* group)
{ {
uint8 icon = Eluna::CHECKVAL<uint8>(L, 2); uint8 icon = Eluna::CHECKVAL<uint8>(E->L, 2);
uint64 target = Eluna::CHECKVAL<uint64>(L, 3); uint64 target = Eluna::CHECKVAL<uint64>(E->L, 3);
uint64 setter = Eluna::CHECKVAL<uint64>(L, 4, 0); uint64 setter = Eluna::CHECKVAL<uint64>(E->L, 4, 0);
if (icon >= TARGETICONCOUNT) if (icon >= TARGETICONCOUNT)
return luaL_argerror(L, 2, "valid target icon expected"); return luaL_argerror(E->L, 2, "valid target icon expected");
#if (defined(CLASSIC) || defined(TBC)) #if (defined(CLASSIC) || defined(TBC))
group->SetTargetIcon(icon, ObjectGuid(target)); group->SetTargetIcon(icon, ObjectGuid(target));
@@ -374,7 +374,7 @@ namespace LuaGroup
return 0; return 0;
} }
/*int ConvertToLFG(lua_State* L, Group* group) // TODO: Implementation /*int ConvertToLFG(Eluna* E, Group* group) // TODO: Implementation
{ {
group->ConvertToLFG(); group->ConvertToLFG();
return 0; return 0;

View File

@@ -10,10 +10,10 @@
namespace LuaGuild namespace LuaGuild
{ {
/* GETTERS */ /* GETTERS */
int GetMembers(lua_State* L, Guild* guild) int GetMembers(Eluna* E, Guild* guild)
{ {
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
SessionMap const& sessions = eWorld->GetAllSessions(); SessionMap const& sessions = eWorld->GetAllSessions();
@@ -24,76 +24,76 @@ namespace LuaGuild
if (player->GetSession() && (player->GetGuildId() == guild->GetId())) if (player->GetSession() && (player->GetGuildId() == guild->GetId()))
{ {
++i; ++i;
Eluna::Push(L, i); Eluna::Push(E->L, i);
Eluna::Push(L, player); Eluna::Push(E->L, player);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
} }
} }
lua_settop(L, tbl); // push table to top of stack lua_settop(E->L, tbl); // push table to top of stack
return 1; return 1;
} }
int GetMemberCount(lua_State* L, Guild* guild) int GetMemberCount(Eluna* E, Guild* guild)
{ {
Eluna::Push(L, guild->GetMemberSize()); Eluna::Push(E->L, guild->GetMemberSize());
return 1; return 1;
} }
int GetLeader(lua_State* L, Guild* guild) int GetLeader(Eluna* E, Guild* guild)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, eObjectAccessor->FindPlayer(guild->GetLeaderGuid())); Eluna::Push(E->L, eObjectAccessor->FindPlayer(guild->GetLeaderGuid()));
#else #else
Eluna::Push(L, eObjectAccessor->FindPlayer(guild->GetLeaderGUID())); Eluna::Push(E->L, eObjectAccessor->FindPlayer(guild->GetLeaderGUID()));
#endif #endif
return 1; return 1;
} }
int GetLeaderGUID(lua_State* L, Guild* guild) int GetLeaderGUID(Eluna* E, Guild* guild)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, guild->GetLeaderGuid()); Eluna::Push(E->L, guild->GetLeaderGuid());
#else #else
Eluna::Push(L, guild->GetLeaderGUID()); Eluna::Push(E->L, guild->GetLeaderGUID());
#endif #endif
return 1; return 1;
} }
int GetId(lua_State* L, Guild* guild) int GetId(Eluna* E, Guild* guild)
{ {
Eluna::Push(L, guild->GetId()); Eluna::Push(E->L, guild->GetId());
return 1; return 1;
} }
int GetName(lua_State* L, Guild* guild) int GetName(Eluna* E, Guild* guild)
{ {
Eluna::Push(L, guild->GetName()); Eluna::Push(E->L, guild->GetName());
return 1; return 1;
} }
int GetMOTD(lua_State* L, Guild* guild) int GetMOTD(Eluna* E, Guild* guild)
{ {
Eluna::Push(L, guild->GetMOTD()); Eluna::Push(E->L, guild->GetMOTD());
return 1; return 1;
} }
int GetInfo(lua_State* L, Guild* guild) int GetInfo(Eluna* E, Guild* guild)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, guild->GetGINFO()); Eluna::Push(E->L, guild->GetGINFO());
#else #else
Eluna::Push(L, guild->GetInfo()); Eluna::Push(E->L, guild->GetInfo());
#endif #endif
return 1; return 1;
} }
/* SETTERS */ /* SETTERS */
#ifndef CATA #ifndef CATA
int SetLeader(lua_State* L, Guild* guild) int SetLeader(Eluna* E, Guild* guild)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
guild->SetLeader(player->GET_GUID()); guild->SetLeader(player->GET_GUID());
@@ -105,10 +105,10 @@ namespace LuaGuild
#endif #endif
#ifndef CLASSIC #ifndef CLASSIC
int SetBankTabText(lua_State* L, Guild* guild) int SetBankTabText(Eluna* E, Guild* guild)
{ {
uint8 tabId = Eluna::CHECKVAL<uint8>(L, 2); uint8 tabId = Eluna::CHECKVAL<uint8>(E->L, 2);
const char* text = Eluna::CHECKVAL<const char*>(L, 3); const char* text = Eluna::CHECKVAL<const char*>(E->L, 3);
#ifndef TRINITY #ifndef TRINITY
guild->SetGuildBankTabText(tabId, text); guild->SetGuildBankTabText(tabId, text);
#else #else
@@ -120,43 +120,43 @@ namespace LuaGuild
/* OTHER */ /* OTHER */
// SendPacketToGuild(packet) // SendPacketToGuild(packet)
int SendPacket(lua_State* L, Guild* guild) int SendPacket(Eluna* E, Guild* guild)
{ {
WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(L, 2); WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(E->L, 2);
guild->BroadcastPacket(data); guild->BroadcastPacket(data);
return 0; return 0;
} }
// SendPacketToRankedInGuild(packet, rankId) // SendPacketToRankedInGuild(packet, rankId)
int SendPacketToRanked(lua_State* L, Guild* guild) int SendPacketToRanked(Eluna* E, Guild* guild)
{ {
WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(L, 2); WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(E->L, 2);
uint8 ranked = Eluna::CHECKVAL<uint8>(L, 3); uint8 ranked = Eluna::CHECKVAL<uint8>(E->L, 3);
guild->BroadcastPacketToRank(data, ranked); guild->BroadcastPacketToRank(data, ranked);
return 0; return 0;
} }
int Disband(lua_State* /*L*/, Guild* guild) int Disband(Eluna* /*E*/, Guild* guild)
{ {
guild->Disband(); guild->Disband();
return 0; return 0;
} }
int AddMember(lua_State* L, Guild* guild) int AddMember(Eluna* E, Guild* guild)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
uint8 rankId = Eluna::CHECKVAL<uint8>(L, 3, GUILD_RANK_NONE); uint8 rankId = Eluna::CHECKVAL<uint8>(E->L, 3, GUILD_RANK_NONE);
guild->AddMember(player->GET_GUID(), rankId); guild->AddMember(player->GET_GUID(), rankId);
return 0; return 0;
} }
int DeleteMember(lua_State* L, Guild* guild) int DeleteMember(Eluna* E, Guild* guild)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
bool isDisbanding = Eluna::CHECKVAL<bool>(L, 3, false); bool isDisbanding = Eluna::CHECKVAL<bool>(E->L, 3, false);
#ifndef TRINITY #ifndef TRINITY
guild->DelMember(player->GET_GUID(), isDisbanding); guild->DelMember(player->GET_GUID(), isDisbanding);
@@ -166,10 +166,10 @@ namespace LuaGuild
return 0; return 0;
} }
int SetMemberRank(lua_State* L, Guild* guild) int SetMemberRank(Eluna* E, Guild* guild)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
uint8 newRank = Eluna::CHECKVAL<uint8>(L, 3); uint8 newRank = Eluna::CHECKVAL<uint8>(E->L, 3);
guild->ChangeMemberRank(player->GET_GUID(), newRank); guild->ChangeMemberRank(player->GET_GUID(), newRank);
return 0; return 0;
@@ -177,10 +177,10 @@ namespace LuaGuild
#ifndef CLASSIC #ifndef CLASSIC
// Move to Player methods // Move to Player methods
int WithdrawBankMoney(lua_State* L, Guild* guild) int WithdrawBankMoney(Eluna* E, Guild* guild)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
uint32 money = Eluna::CHECKVAL<uint32>(L, 3); uint32 money = Eluna::CHECKVAL<uint32>(E->L, 3);
#ifndef TRINITY #ifndef TRINITY
if (guild->GetGuildBankMoney() < money) if (guild->GetGuildBankMoney() < money)
return 0; return 0;
@@ -192,10 +192,10 @@ namespace LuaGuild
} }
// Move to Player methods // Move to Player methods
int DepositBankMoney(lua_State* L, Guild* guild) int DepositBankMoney(Eluna* E, Guild* guild)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
uint32 money = Eluna::CHECKVAL<uint32>(L, 3); uint32 money = Eluna::CHECKVAL<uint32>(E->L, 3);
#ifndef TRINITY #ifndef TRINITY
guild->SetBankMoney(guild->GetGuildBankMoney() + money); guild->SetBankMoney(guild->GetGuildBankMoney() + money);

View File

@@ -46,12 +46,12 @@ using namespace HookMgr;
#define EVENT_BEGIN(BINDMAP, EVENT, RET) \ #define EVENT_BEGIN(BINDMAP, EVENT, RET) \
if (!BINDMAP->HasEvents(EVENT)) \ if (!BINDMAP->HasEvents(EVENT)) \
RET; \ RET; \
lua_State* L = sEluna->L; \ lua_State* L = this->L; \
const char* _LuaBindType = sEluna->BINDMAP->groupName; \ const char* _LuaBindType = this->BINDMAP->groupName; \
uint32 _LuaEvent = EVENT; \ uint32 _LuaEvent = EVENT; \
int _LuaStackTop = lua_gettop(L); \ int _LuaStackTop = lua_gettop(L); \
for (size_t i = 0; i < sEluna->BINDMAP->Bindings[_LuaEvent].size(); ++i) \ for (size_t i = 0; i < this->BINDMAP->Bindings[_LuaEvent].size(); ++i) \
lua_rawgeti(L, LUA_REGISTRYINDEX, (sEluna->BINDMAP->Bindings[_LuaEvent][i])); \ lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[_LuaEvent][i])); \
int _LuaFuncTop = lua_gettop(L); \ int _LuaFuncTop = lua_gettop(L); \
int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \ int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \
Eluna::Push(L, _LuaEvent); Eluna::Push(L, _LuaEvent);
@@ -69,7 +69,7 @@ using namespace HookMgr;
{ \ { \
for (int i = 0; i <= _LuaParams; ++i) \ for (int i = 0; i <= _LuaParams; ++i) \
lua_pushvalue(L, _LuaFuncTop+i); \ lua_pushvalue(L, _LuaFuncTop+i); \
Eluna::ExecuteCall(L, _LuaParams, _LuaReturnValues); \ Eluna::ExecuteCall(_LuaParams, _LuaReturnValues); \
lua_remove(L, _LuaFuncTop--); \ lua_remove(L, _LuaFuncTop--); \
} \ } \
for (int i = _LuaParams; i > 0; --i) \ for (int i = _LuaParams; i > 0; --i) \
@@ -78,11 +78,11 @@ using namespace HookMgr;
// RET is a return statement // RET is a return statement
#define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \ #define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \
int _Luabind = sEluna->BINDMAP->GetBind(ENTRY, EVENT); \ int _Luabind = this->BINDMAP->GetBind(ENTRY, EVENT); \
if (!_Luabind) \ if (!_Luabind) \
RET; \ RET; \
lua_State* L = sEluna->L; \ lua_State* L = this->L; \
const char* _LuaBindType = sEluna->BINDMAP->groupName; \ const char* _LuaBindType = this->BINDMAP->groupName; \
uint32 _LuaEvent = EVENT; \ uint32 _LuaEvent = EVENT; \
int _LuaStackTop = lua_gettop(L); \ int _LuaStackTop = lua_gettop(L); \
lua_rawgeti(L, LUA_REGISTRYINDEX, _Luabind); \ lua_rawgeti(L, LUA_REGISTRYINDEX, _Luabind); \
@@ -93,7 +93,7 @@ using namespace HookMgr;
#define ENTRY_EXECUTE(RETVALS) \ #define ENTRY_EXECUTE(RETVALS) \
int _LuaReturnValues = RETVALS; \ int _LuaReturnValues = RETVALS; \
int _LuaParams = lua_gettop(L) - _LuaStackTop - 1; \ int _LuaParams = lua_gettop(L) - _LuaStackTop - 1; \
Eluna::ExecuteCall(L, _LuaParams, _LuaReturnValues); Eluna::ExecuteCall(_LuaParams, _LuaReturnValues);
#define FOR_RETS(IT) \ #define FOR_RETS(IT) \
for (int IT = _LuaStackTop + 1; IT <= lua_gettop(L); ++IT) for (int IT = _LuaStackTop + 1; IT <= lua_gettop(L); ++IT)
@@ -107,7 +107,9 @@ using namespace HookMgr;
{ \ { \
ELUNA_LOG_ERROR("[Eluna]: Ending event %u for %s, stack top was %i and was supposed to be between %i and %i. Report to devs", _LuaEvent, _LuaBindType, lua_gettop(L), _LuaStackTop, _LuaStackTop + _LuaFuncCount * _LuaReturnValues); \ ELUNA_LOG_ERROR("[Eluna]: Ending event %u for %s, stack top was %i and was supposed to be between %i and %i. Report to devs", _LuaEvent, _LuaBindType, lua_gettop(L), _LuaStackTop, _LuaStackTop + _LuaFuncCount * _LuaReturnValues); \
} \ } \
lua_settop(L, _LuaStackTop); lua_settop(L, _LuaStackTop); \
if (!this->event_level) \
this->InvalidateObjects(); // Invalidate objects on outermost hook call
void Eluna::OnLuaStateClose() void Eluna::OnLuaStateClose()
{ {
@@ -341,14 +343,14 @@ void Eluna::OnShutdownCancel()
void Eluna::OnWorldUpdate(uint32 diff) void Eluna::OnWorldUpdate(uint32 diff)
{ {
eventMgr->globalProcessor->Update(diff);
if (reload) if (reload)
{ {
ReloadEluna(); ReloadEluna();
return; return;
} }
eventMgr->globalProcessor->Update(diff);
EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_UPDATE, return); EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_UPDATE, return);
Push(L, diff); Push(L, diff);
EVENT_EXECUTE(0); EVENT_EXECUTE(0);
@@ -1320,6 +1322,8 @@ void Eluna::OnPlayerLeave(Map* map, Player* player)
} }
void Eluna::OnUpdate(Map* map, uint32 diff) void Eluna::OnUpdate(Map* map, uint32 diff)
{ {
// enable this for multithread
// eventMgr->globalProcessor->Update(diff);
EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_UPDATE, return); EVENT_BEGIN(ServerEventBindings, MAP_EVENT_ON_UPDATE, return);
Push(L, map); Push(L, map);
Push(L, diff); Push(L, diff);
@@ -1450,6 +1454,242 @@ void Eluna::OnRemoveFromWorld(Creature* creature)
ENDCALL(); ENDCALL();
} }
void Eluna::UpdateAI(Creature* me, const uint32 diff)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE, return);
Eluna::Push(L, me);
Eluna::Push(L, diff);
ENTRY_EXECUTE(0);
ENDCALL();
}
//Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
//Called at creature aggro either by MoveInLOS or Attack Start
void Eluna::EnterCombat(Creature* me, Unit* target)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT, return);
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called at any Damage from any attacker (before damage apply)
void Eluna::DamageTaken(Creature* me, Unit* attacker, uint32& damage)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN, return);
Eluna::Push(L, me);
Eluna::Push(L, attacker);
Eluna::Push(L, damage);
ENTRY_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
damage = Eluna::CHECKVAL<uint32>(L, i, damage);
}
ENDCALL();
}
//Called at creature death
void Eluna::JustDied(Creature* me, Unit* killer)
{
On_Reset(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DIED, return);
Eluna::Push(L, me);
Eluna::Push(L, killer);
ENTRY_EXECUTE(0);
ENDCALL();
}
//Called at creature killing another unit
void Eluna::KilledUnit(Creature* me, Unit* victim)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED, return);
Eluna::Push(L, me);
Eluna::Push(L, victim);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when the creature summon successfully other creature
void Eluna::JustSummoned(Creature* me, Creature* summon)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, return);
Eluna::Push(L, me);
Eluna::Push(L, summon);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when a summoned creature is despawned
void Eluna::SummonedCreatureDespawn(Creature* me, Creature* summon)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN, return);
Eluna::Push(L, me);
Eluna::Push(L, summon);
ENTRY_EXECUTE(0);
ENDCALL();
}
//Called at waypoint reached or PointMovement end
void Eluna::MovementInform(Creature* me, uint32 type, uint32 id)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_WP, return);
Eluna::Push(L, me);
Eluna::Push(L, type);
Eluna::Push(L, id);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called before EnterCombat even before the creature is in combat.
void Eluna::AttackStart(Creature* me, Unit* target)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT, return);
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called for reaction at stopping attack at no attackers or targets
void Eluna::EnterEvadeMode(Creature* me)
{
On_Reset(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
void Eluna::AttackedBy(Creature* me, Unit* attacker)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT, return);
Eluna::Push(L, me);
Eluna::Push(L, attacker);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when creature is spawned or respawned (for reseting variables)
void Eluna::JustRespawned(Creature* me)
{
On_Reset(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called at reaching home after evade
void Eluna::JustReachedHome(Creature* me)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called at text emote receive from player
void Eluna::ReceiveEmote(Creature* me, Player* player, uint32 emoteId)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE, return);
Eluna::Push(L, me);
Eluna::Push(L, player);
Eluna::Push(L, emoteId);
ENTRY_EXECUTE(0);
ENDCALL();
}
// called when the corpse of this creature gets removed
void Eluna::CorpseRemoved(Creature* me, uint32& respawnDelay)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED, return);
Eluna::Push(L, me);
Eluna::Push(L, respawnDelay);
ENTRY_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
respawnDelay = Eluna::CHECKVAL<uint32>(L, i, respawnDelay);
}
ENDCALL();
}
void Eluna::MoveInLineOfSight(Creature* me, Unit* who)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS, return);
Eluna::Push(L, me);
Eluna::Push(L, who);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called on creature initial spawn, respawn, death, evade (leave combat)
void Eluna::On_Reset(Creature* me) // Not an override, custom
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RESET, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when hit by a spell
void Eluna::SpellHit(Creature* me, Unit* caster, SpellInfo const* spell)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL, return);
Eluna::Push(L, me);
Eluna::Push(L, caster);
Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when spell hits a target
void Eluna::SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET, return);
Eluna::Push(L, me);
Eluna::Push(L, target);
Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(0);
ENDCALL();
}
#ifdef TRINITY
void Eluna::SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, return);
Eluna::Push(L, me);
Eluna::Push(L, summon);
Eluna::Push(L, killer);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when owner takes damage
void Eluna::OwnerAttackedBy(Creature* me, Unit* attacker)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT, return);
Eluna::Push(L, me);
Eluna::Push(L, attacker);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called when owner attacks something
void Eluna::OwnerAttacked(Creature* me, Unit* target)
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED, return);
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(0);
ENDCALL();
}
#endif
struct ElunaCreatureAI : ScriptedAI struct ElunaCreatureAI : ScriptedAI
{ {
#ifndef TRINITY #ifndef TRINITY
@@ -1476,11 +1716,8 @@ struct ElunaCreatureAI : ScriptedAI
if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE)) if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE))
ScriptedAI::UpdateAI(diff); ScriptedAI::UpdateAI(diff);
#endif #endif
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE, return);
Eluna::Push(L, me); sEluna->UpdateAI(me, diff);
Eluna::Push(L, diff);
ENTRY_EXECUTE(0);
ENDCALL();
} }
//Called for reaction at enter to combat if not in combat yet (enemy can be NULL) //Called for reaction at enter to combat if not in combat yet (enemy can be NULL)
@@ -1488,167 +1725,98 @@ struct ElunaCreatureAI : ScriptedAI
void EnterCombat(Unit* target) override void EnterCombat(Unit* target) override
{ {
ScriptedAI::EnterCombat(target); ScriptedAI::EnterCombat(target);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT, return); sEluna->EnterCombat(me, target);
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called at any Damage from any attacker (before damage apply) // Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* attacker, uint32& damage) override void DamageTaken(Unit* attacker, uint32& damage) override
{ {
ScriptedAI::DamageTaken(attacker, damage); ScriptedAI::DamageTaken(attacker, damage);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN, return); sEluna->DamageTaken(me, attacker, damage);
Eluna::Push(L, me);
Eluna::Push(L, attacker);
Eluna::Push(L, damage);
ENTRY_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
damage = Eluna::CHECKVAL<uint32>(L, i, damage);
}
ENDCALL();
} }
//Called at creature death //Called at creature death
void JustDied(Unit* killer) override void JustDied(Unit* killer) override
{ {
ScriptedAI::JustDied(killer); ScriptedAI::JustDied(killer);
On_Reset(); sEluna->JustDied(me, killer);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_DIED, return);
Eluna::Push(L, me);
Eluna::Push(L, killer);
ENTRY_EXECUTE(0);
ENDCALL();
} }
//Called at creature killing another unit //Called at creature killing another unit
void KilledUnit(Unit* victim) override void KilledUnit(Unit* victim) override
{ {
ScriptedAI::KilledUnit(victim); ScriptedAI::KilledUnit(victim);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED, return); sEluna->KilledUnit(me, victim);
Eluna::Push(L, me);
Eluna::Push(L, victim);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when the creature summon successfully other creature // Called when the creature summon successfully other creature
void JustSummoned(Creature* summon) override void JustSummoned(Creature* summon) override
{ {
ScriptedAI::JustSummoned(summon); ScriptedAI::JustSummoned(summon);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE, return); sEluna->JustSummoned(me, summon);
Eluna::Push(L, me);
Eluna::Push(L, summon);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when a summoned creature is despawned // Called when a summoned creature is despawned
void SummonedCreatureDespawn(Creature* summon) override void SummonedCreatureDespawn(Creature* summon) override
{ {
ScriptedAI::SummonedCreatureDespawn(summon); ScriptedAI::SummonedCreatureDespawn(summon);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN, return); sEluna->SummonedCreatureDespawn(me, summon);
Eluna::Push(L, me);
Eluna::Push(L, summon);
ENTRY_EXECUTE(0);
ENDCALL();
} }
//Called at waypoint reached or PointMovement end //Called at waypoint reached or PointMovement end
void MovementInform(uint32 type, uint32 id) override void MovementInform(uint32 type, uint32 id) override
{ {
ScriptedAI::MovementInform(type, id); ScriptedAI::MovementInform(type, id);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_WP, return); sEluna->MovementInform(me, type, id);
Eluna::Push(L, me);
Eluna::Push(L, type);
Eluna::Push(L, id);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called before EnterCombat even before the creature is in combat. // Called before EnterCombat even before the creature is in combat.
void AttackStart(Unit* target) override void AttackStart(Unit* target) override
{ {
ScriptedAI::AttackStart(target); ScriptedAI::AttackStart(target);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT, return); sEluna->AttackStart(me, target);
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called for reaction at stopping attack at no attackers or targets // Called for reaction at stopping attack at no attackers or targets
void EnterEvadeMode() override void EnterEvadeMode() override
{ {
ScriptedAI::EnterEvadeMode(); ScriptedAI::EnterEvadeMode();
On_Reset(); sEluna->EnterEvadeMode(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
void AttackedBy(Unit* attacker) override void AttackedBy(Unit* attacker) override
{ {
ScriptedAI::AttackedBy(attacker); ScriptedAI::AttackedBy(attacker);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT, return); sEluna->AttackedBy(me, attacker);
Eluna::Push(L, me);
Eluna::Push(L, attacker);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when creature is spawned or respawned (for reseting variables) // Called when creature is spawned or respawned (for reseting variables)
void JustRespawned() override void JustRespawned() override
{ {
ScriptedAI::JustRespawned(); ScriptedAI::JustRespawned();
On_Reset(); sEluna->JustRespawned(me);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPAWN, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called at reaching home after evade // Called at reaching home after evade
void JustReachedHome() override void JustReachedHome() override
{ {
ScriptedAI::JustReachedHome(); ScriptedAI::JustReachedHome();
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME, return); sEluna->JustReachedHome(me);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called at text emote receive from player // Called at text emote receive from player
void ReceiveEmote(Player* player, uint32 emoteId) override void ReceiveEmote(Player* player, uint32 emoteId) override
{ {
ScriptedAI::ReceiveEmote(player, emoteId); ScriptedAI::ReceiveEmote(player, emoteId);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE, return); sEluna->ReceiveEmote(me, player, emoteId);
Eluna::Push(L, me);
Eluna::Push(L, player);
Eluna::Push(L, emoteId);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// called when the corpse of this creature gets removed // called when the corpse of this creature gets removed
void CorpseRemoved(uint32& respawnDelay) override void CorpseRemoved(uint32& respawnDelay) override
{ {
ScriptedAI::CorpseRemoved(respawnDelay); ScriptedAI::CorpseRemoved(respawnDelay);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED, return); sEluna->CorpseRemoved(me, respawnDelay);
Eluna::Push(L, me);
Eluna::Push(L, respawnDelay);
ENTRY_EXECUTE(1);
FOR_RETS(i)
{
if (lua_isnumber(L, i))
respawnDelay = Eluna::CHECKVAL<uint32>(L, i, respawnDelay);
}
ENDCALL();
} }
#ifndef TRINITY #ifndef TRINITY
@@ -1662,44 +1830,21 @@ struct ElunaCreatureAI : ScriptedAI
void MoveInLineOfSight(Unit* who) override void MoveInLineOfSight(Unit* who) override
{ {
ScriptedAI::MoveInLineOfSight(who); ScriptedAI::MoveInLineOfSight(who);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS, return); sEluna->MoveInLineOfSight(me, who);
Eluna::Push(L, me);
Eluna::Push(L, who);
ENTRY_EXECUTE(0);
ENDCALL();
}
// Called on creature initial spawn, respawn, death, evade (leave combat)
void On_Reset() // Not an override, custom
{
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_RESET, return);
Eluna::Push(L, me);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when hit by a spell // Called when hit by a spell
void SpellHit(Unit* caster, SpellInfo const* spell) override void SpellHit(Unit* caster, SpellInfo const* spell) override
{ {
ScriptedAI::SpellHit(caster, spell); ScriptedAI::SpellHit(caster, spell);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL, return); sEluna->SpellHit(me, caster, spell);
Eluna::Push(L, me);
Eluna::Push(L, caster);
Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when spell hits a target // Called when spell hits a target
void SpellHitTarget(Unit* target, SpellInfo const* spell) override void SpellHitTarget(Unit* target, SpellInfo const* spell) override
{ {
ScriptedAI::SpellHitTarget(target, spell); ScriptedAI::SpellHitTarget(target, spell);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET, return); sEluna->SpellHitTarget(me, target, spell);
Eluna::Push(L, me);
Eluna::Push(L, target);
Eluna::Push(L, spell->Id); // Pass spell object?
ENTRY_EXECUTE(0);
ENDCALL();
} }
#ifdef TRINITY #ifdef TRINITY
@@ -1714,34 +1859,21 @@ struct ElunaCreatureAI : ScriptedAI
void SummonedCreatureDies(Creature* summon, Unit* killer) override void SummonedCreatureDies(Creature* summon, Unit* killer) override
{ {
ScriptedAI::SummonedCreatureDies(summon, killer); ScriptedAI::SummonedCreatureDies(summon, killer);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED, return); sEluna->SummonedCreatureDies(me, summon, killer);
Eluna::Push(L, me);
Eluna::Push(L, summon);
Eluna::Push(L, killer);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when owner takes damage // Called when owner takes damage
void OwnerAttackedBy(Unit* attacker) override void OwnerAttackedBy(Unit* attacker) override
{ {
ScriptedAI::OwnerAttackedBy(attacker); ScriptedAI::OwnerAttackedBy(attacker);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT, return); sEluna->OwnerAttackedBy(me, attacker);
Eluna::Push(L, me);
Eluna::Push(L, attacker);
ENTRY_EXECUTE(0);
ENDCALL();
} }
// Called when owner attacks something // Called when owner attacks something
void OwnerAttacked(Unit* target) override void OwnerAttacked(Unit* target) override
{ {
ScriptedAI::OwnerAttacked(target); ScriptedAI::OwnerAttacked(target);
ENTRY_BEGIN(CreatureEventBindings, me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED, return); sEluna->OwnerAttacked(me, target);
Eluna::Push(L, me);
Eluna::Push(L, target);
ENTRY_EXECUTE(0);
ENDCALL();
} }
#endif #endif

View File

@@ -10,136 +10,136 @@
namespace LuaItem namespace LuaItem
{ {
/* BOOLEAN */ /* BOOLEAN */
int IsSoulBound(lua_State* L, Item* item) int IsSoulBound(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsSoulBound()); Eluna::Push(E->L, item->IsSoulBound());
return 1; return 1;
} }
#if (!defined(TBC) && !defined(CLASSIC)) #if (!defined(TBC) && !defined(CLASSIC))
int IsBoundAccountWide(lua_State* L, Item* item) int IsBoundAccountWide(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsBoundAccountWide()); Eluna::Push(E->L, item->IsBoundAccountWide());
return 1; return 1;
} }
#endif #endif
int IsBoundByEnchant(lua_State* L, Item* item) int IsBoundByEnchant(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsBoundByEnchant()); Eluna::Push(E->L, item->IsBoundByEnchant());
return 1; return 1;
} }
int IsNotBoundToPlayer(lua_State* L, Item* item) int IsNotBoundToPlayer(Eluna* E, Item* item)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
Eluna::Push(L, item->IsBindedNotWith(player)); Eluna::Push(E->L, item->IsBindedNotWith(player));
return 1; return 1;
} }
int IsLocked(lua_State* L, Item* item) int IsLocked(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsLocked()); Eluna::Push(E->L, item->IsLocked());
return 1; return 1;
} }
int IsBag(lua_State* L, Item* item) int IsBag(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsBag()); Eluna::Push(E->L, item->IsBag());
return 1; return 1;
} }
#ifndef CLASSIC #ifndef CLASSIC
int IsCurrencyToken(lua_State* L, Item* item) int IsCurrencyToken(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsCurrencyToken()); Eluna::Push(E->L, item->IsCurrencyToken());
return 1; return 1;
} }
#endif #endif
int IsNotEmptyBag(lua_State* L, Item* item) int IsNotEmptyBag(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsNotEmptyBag()); Eluna::Push(E->L, item->IsNotEmptyBag());
return 1; return 1;
} }
int IsBroken(lua_State* L, Item* item) int IsBroken(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsBroken()); Eluna::Push(E->L, item->IsBroken());
return 1; return 1;
} }
int CanBeTraded(lua_State* L, Item* item) int CanBeTraded(Eluna* E, Item* item)
{ {
#if (defined(TBC) || defined(CLASSIC)) #if (defined(TBC) || defined(CLASSIC))
Eluna::Push(L, item->CanBeTraded()); Eluna::Push(E->L, item->CanBeTraded());
#else #else
bool mail = Eluna::CHECKVAL<bool>(L, 2, false); bool mail = Eluna::CHECKVAL<bool>(E->L, 2, false);
Eluna::Push(L, item->CanBeTraded(mail)); Eluna::Push(E->L, item->CanBeTraded(mail));
#endif #endif
return 1; return 1;
} }
int IsInTrade(lua_State* L, Item* item) int IsInTrade(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsInTrade()); Eluna::Push(E->L, item->IsInTrade());
return 1; return 1;
} }
int IsInBag(lua_State* L, Item* item) int IsInBag(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsInBag()); Eluna::Push(E->L, item->IsInBag());
return 1; return 1;
} }
int IsEquipped(lua_State* L, Item* item) int IsEquipped(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsEquipped()); Eluna::Push(E->L, item->IsEquipped());
return 1; return 1;
} }
int HasQuest(lua_State* L, Item* item) int HasQuest(Eluna* E, Item* item)
{ {
uint32 quest = Eluna::CHECKVAL<uint32>(L, 2); uint32 quest = Eluna::CHECKVAL<uint32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, item->HasQuest(quest)); Eluna::Push(E->L, item->HasQuest(quest));
#else #else
Eluna::Push(L, item->hasQuest(quest)); Eluna::Push(E->L, item->hasQuest(quest));
#endif #endif
return 1; return 1;
} }
int IsPotion(lua_State* L, Item* item) int IsPotion(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsPotion()); Eluna::Push(E->L, item->IsPotion());
return 1; return 1;
} }
#ifndef CATA #ifndef CATA
int IsWeaponVellum(lua_State* L, Item* item) int IsWeaponVellum(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsWeaponVellum()); Eluna::Push(E->L, item->IsWeaponVellum());
return 1; return 1;
} }
int IsArmorVellum(lua_State* L, Item* item) int IsArmorVellum(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsArmorVellum()); Eluna::Push(E->L, item->IsArmorVellum());
return 1; return 1;
} }
#endif #endif
int IsConjuredConsumable(lua_State* L, Item* item) int IsConjuredConsumable(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->IsConjuredConsumable()); Eluna::Push(E->L, item->IsConjuredConsumable());
return 1; return 1;
} }
/* /*
* int IsRefundExpired(lua_State* L, Item* item)// TODO: Implement core support * int IsRefundExpired(Eluna* E, Item* item)// TODO: Implement core support
* { * {
* Eluna::Push(L, item->IsRefundExpired()); * Eluna::Push(E->L, item->IsRefundExpired());
* return 1; * return 1;
* } * }
*/ */
@@ -167,11 +167,11 @@ namespace LuaItem
* @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the [Item]'s name in * @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the [Item]'s name in
* @return string itemLink * @return string itemLink
*/ */
int GetItemLink(lua_State* L, Item* item) int GetItemLink(Eluna* E, Item* item)
{ {
uint8 locale = Eluna::CHECKVAL<uint8>(L, 2, DEFAULT_LOCALE); uint8 locale = Eluna::CHECKVAL<uint8>(E->L, 2, DEFAULT_LOCALE);
if (locale >= TOTAL_LOCALES) if (locale >= TOTAL_LOCALES)
return luaL_argerror(L, 2, "valid LocaleConstant expected"); return luaL_argerror(E->L, 2, "valid LocaleConstant expected");
const ItemTemplate* temp = item->GetTemplate(); const ItemTemplate* temp = item->GetTemplate();
std::string name = temp->Name1; std::string name = temp->Name1;
@@ -223,200 +223,200 @@ namespace LuaItem
item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" << item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" <<
(uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r"; (uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r";
Eluna::Push(L, oss.str()); Eluna::Push(E->L, oss.str());
return 1; return 1;
} }
int GetOwnerGUID(lua_State* L, Item* item) int GetOwnerGUID(Eluna* E, Item* item)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, item->GetOwnerGuid()); Eluna::Push(E->L, item->GetOwnerGuid());
#else #else
Eluna::Push(L, item->GetOwnerGUID()); Eluna::Push(E->L, item->GetOwnerGUID());
#endif #endif
return 1; return 1;
} }
int GetOwner(lua_State* L, Item* item) int GetOwner(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetOwner()); Eluna::Push(E->L, item->GetOwner());
return 1; return 1;
} }
int GetCount(lua_State* L, Item* item) int GetCount(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetCount()); Eluna::Push(E->L, item->GetCount());
return 1; return 1;
} }
int GetMaxStackCount(lua_State* L, Item* item) int GetMaxStackCount(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetMaxStackCount()); Eluna::Push(E->L, item->GetMaxStackCount());
return 1; return 1;
} }
int GetSlot(lua_State* L, Item* item) int GetSlot(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetSlot()); Eluna::Push(E->L, item->GetSlot());
return 1; return 1;
} }
int GetBagSlot(lua_State* L, Item* item) int GetBagSlot(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetBagSlot()); Eluna::Push(E->L, item->GetBagSlot());
return 1; return 1;
} }
int GetEnchantmentId(lua_State* L, Item* item) int GetEnchantmentId(Eluna* E, Item* item)
{ {
uint32 enchant_slot = Eluna::CHECKVAL<uint32>(L, 2); uint32 enchant_slot = Eluna::CHECKVAL<uint32>(E->L, 2);
if (enchant_slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) if (enchant_slot >= MAX_INSPECTED_ENCHANTMENT_SLOT)
return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); return luaL_argerror(E->L, 2, "valid EnchantmentSlot expected");
Eluna::Push(L, item->GetEnchantmentId(EnchantmentSlot(enchant_slot))); Eluna::Push(E->L, item->GetEnchantmentId(EnchantmentSlot(enchant_slot)));
return 1; return 1;
} }
int GetSpellId(lua_State* L, Item* item) int GetSpellId(Eluna* E, Item* item)
{ {
uint32 index = Eluna::CHECKVAL<uint32>(L, 2); uint32 index = Eluna::CHECKVAL<uint32>(E->L, 2);
if (index >= MAX_ITEM_PROTO_SPELLS) if (index >= MAX_ITEM_PROTO_SPELLS)
return luaL_argerror(L, 2, "valid SpellIndex expected"); return luaL_argerror(E->L, 2, "valid SpellIndex expected");
Eluna::Push(L, item->GetTemplate()->Spells[index].SpellId); Eluna::Push(E->L, item->GetTemplate()->Spells[index].SpellId);
return 1; return 1;
} }
int GetSpellTrigger(lua_State* L, Item* item) int GetSpellTrigger(Eluna* E, Item* item)
{ {
uint32 index = Eluna::CHECKVAL<uint32>(L, 2); uint32 index = Eluna::CHECKVAL<uint32>(E->L, 2);
if (index >= MAX_ITEM_PROTO_SPELLS) if (index >= MAX_ITEM_PROTO_SPELLS)
return luaL_argerror(L, 2, "valid SpellIndex expected"); return luaL_argerror(E->L, 2, "valid SpellIndex expected");
Eluna::Push(L, item->GetTemplate()->Spells[index].SpellTrigger); Eluna::Push(E->L, item->GetTemplate()->Spells[index].SpellTrigger);
return 1; return 1;
} }
int GetClass(lua_State* L, Item* item) int GetClass(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->Class); Eluna::Push(E->L, item->GetTemplate()->Class);
return 1; return 1;
} }
int GetSubClass(lua_State* L, Item* item) int GetSubClass(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->SubClass); Eluna::Push(E->L, item->GetTemplate()->SubClass);
return 1; return 1;
} }
int GetName(lua_State* L, Item* item) int GetName(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->Name1); Eluna::Push(E->L, item->GetTemplate()->Name1);
return 1; return 1;
} }
int GetDisplayId(lua_State* L, Item* item) int GetDisplayId(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->DisplayInfoID); Eluna::Push(E->L, item->GetTemplate()->DisplayInfoID);
return 1; return 1;
} }
int GetQuality(lua_State* L, Item* item) int GetQuality(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->Quality); Eluna::Push(E->L, item->GetTemplate()->Quality);
return 1; return 1;
} }
int GetBuyCount(lua_State* L, Item* item) int GetBuyCount(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->BuyCount); Eluna::Push(E->L, item->GetTemplate()->BuyCount);
return 1; return 1;
} }
int GetBuyPrice(lua_State* L, Item* item) int GetBuyPrice(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->BuyPrice); Eluna::Push(E->L, item->GetTemplate()->BuyPrice);
return 1; return 1;
} }
int GetSellPrice(lua_State* L, Item* item) int GetSellPrice(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->SellPrice); Eluna::Push(E->L, item->GetTemplate()->SellPrice);
return 1; return 1;
} }
int GetInventoryType(lua_State* L, Item* item) int GetInventoryType(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->InventoryType); Eluna::Push(E->L, item->GetTemplate()->InventoryType);
return 1; return 1;
} }
int GetAllowableClass(lua_State* L, Item* item) int GetAllowableClass(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->AllowableClass); Eluna::Push(E->L, item->GetTemplate()->AllowableClass);
return 1; return 1;
} }
int GetAllowableRace(lua_State* L, Item* item) int GetAllowableRace(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->AllowableRace); Eluna::Push(E->L, item->GetTemplate()->AllowableRace);
return 1; return 1;
} }
int GetItemLevel(lua_State* L, Item* item) int GetItemLevel(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->ItemLevel); Eluna::Push(E->L, item->GetTemplate()->ItemLevel);
return 1; return 1;
} }
int GetRequiredLevel(lua_State* L, Item* item) int GetRequiredLevel(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->RequiredLevel); Eluna::Push(E->L, item->GetTemplate()->RequiredLevel);
return 1; return 1;
} }
#ifdef WOTLK #ifdef WOTLK
int GetStatsCount(lua_State* L, Item* item) int GetStatsCount(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->StatsCount); Eluna::Push(E->L, item->GetTemplate()->StatsCount);
return 1; return 1;
} }
#endif #endif
int GetRandomProperty(lua_State* L, Item* item) int GetRandomProperty(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->RandomProperty); Eluna::Push(E->L, item->GetTemplate()->RandomProperty);
return 1; return 1;
} }
#ifndef CLASSIC #ifndef CLASSIC
int GetRandomSuffix(lua_State* L, Item* item) int GetRandomSuffix(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->RandomSuffix); Eluna::Push(E->L, item->GetTemplate()->RandomSuffix);
return 1; return 1;
} }
#endif #endif
int GetItemSet(lua_State* L, Item* item) int GetItemSet(Eluna* E, Item* item)
{ {
Eluna::Push(L, item->GetTemplate()->ItemSet); Eluna::Push(E->L, item->GetTemplate()->ItemSet);
return 1; return 1;
} }
int GetBagSize(lua_State* L, Item* item) int GetBagSize(Eluna* E, Item* item)
{ {
if (Bag* bag = item->ToBag()) if (Bag* bag = item->ToBag())
Eluna::Push(L, bag->GetBagSize()); Eluna::Push(E->L, bag->GetBagSize());
else else
Eluna::Push(L, 0); Eluna::Push(E->L, 0);
return 1; return 1;
} }
/* SETTERS */ /* SETTERS */
int SetOwner(lua_State* L, Item* item) int SetOwner(Eluna* E, Item* item)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
item->SetOwnerGuid(player->GET_GUID()); item->SetOwnerGuid(player->GET_GUID());
#else #else
@@ -425,75 +425,75 @@ namespace LuaItem
return 0; return 0;
} }
int SetBinding(lua_State* L, Item* item) int SetBinding(Eluna* E, Item* item)
{ {
bool soulbound = Eluna::CHECKVAL<bool>(L, 2); bool soulbound = Eluna::CHECKVAL<bool>(E->L, 2);
item->SetBinding(soulbound); item->SetBinding(soulbound);
return 0; return 0;
} }
int SetCount(lua_State* L, Item* item) int SetCount(Eluna* E, Item* item)
{ {
uint32 count = Eluna::CHECKVAL<uint32>(L, 2); uint32 count = Eluna::CHECKVAL<uint32>(E->L, 2);
item->SetCount(count); item->SetCount(count);
return 0; return 0;
} }
int SetEnchantment(lua_State* L, Item* item) int SetEnchantment(Eluna* E, Item* item)
{ {
Player* owner = item->GetOwner(); Player* owner = item->GetOwner();
if (!owner) if (!owner)
{ {
Eluna::Push(L, false); Eluna::Push(E->L, false);
return 1; return 1;
} }
uint32 enchant = Eluna::CHECKVAL<uint32>(L, 2); uint32 enchant = Eluna::CHECKVAL<uint32>(E->L, 2);
if (!sSpellItemEnchantmentStore.LookupEntry(enchant)) if (!sSpellItemEnchantmentStore.LookupEntry(enchant))
{ {
Eluna::Push(L, false); Eluna::Push(E->L, false);
return 1; return 1;
} }
EnchantmentSlot slot = (EnchantmentSlot)Eluna::CHECKVAL<uint32>(L, 3); EnchantmentSlot slot = (EnchantmentSlot)Eluna::CHECKVAL<uint32>(E->L, 3);
if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT)
return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); return luaL_argerror(E->L, 2, "valid EnchantmentSlot expected");
owner->ApplyEnchantment(item, slot, false); owner->ApplyEnchantment(item, slot, false);
item->SetEnchantment(slot, enchant, 0, 0); item->SetEnchantment(slot, enchant, 0, 0);
owner->ApplyEnchantment(item, slot, true); owner->ApplyEnchantment(item, slot, true);
Eluna::Push(L, true); Eluna::Push(E->L, true);
return 1; return 1;
} }
/* OTHER */ /* OTHER */
int ClearEnchantment(lua_State* L, Item* item) int ClearEnchantment(Eluna* E, Item* item)
{ {
Player* owner = item->GetOwner(); Player* owner = item->GetOwner();
if (!owner) if (!owner)
{ {
Eluna::Push(L, false); Eluna::Push(E->L, false);
return 1; return 1;
} }
EnchantmentSlot slot = (EnchantmentSlot)Eluna::CHECKVAL<uint32>(L, 2); EnchantmentSlot slot = (EnchantmentSlot)Eluna::CHECKVAL<uint32>(E->L, 2);
if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT)
return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); return luaL_argerror(E->L, 2, "valid EnchantmentSlot expected");
if (!item->GetEnchantmentId(slot)) if (!item->GetEnchantmentId(slot))
{ {
Eluna::Push(L, false); Eluna::Push(E->L, false);
return 1; return 1;
} }
owner->ApplyEnchantment(item, slot, false); owner->ApplyEnchantment(item, slot, false);
item->ClearEnchantment(slot); item->ClearEnchantment(slot);
Eluna::Push(L, true); Eluna::Push(E->L, true);
return 1; return 1;
} }
int SaveToDB(lua_State* /*L*/, Item* item) int SaveToDB(Eluna* /*E*/, Item* item)
{ {
#ifndef TRINITY #ifndef TRINITY
item->SaveToDB(); item->SaveToDB();

View File

@@ -32,11 +32,14 @@ std::string Eluna::lua_folderpath;
std::string Eluna::lua_requirepath; std::string Eluna::lua_requirepath;
Eluna* Eluna::GEluna = NULL; Eluna* Eluna::GEluna = NULL;
bool Eluna::reload = false; bool Eluna::reload = false;
bool Eluna::initialized = false;
extern void RegisterFunctions(lua_State* L); extern void RegisterFunctions(Eluna* E);
void Eluna::Initialize() void Eluna::Initialize()
{ {
ASSERT(!initialized);
uint32 oldMSTime = ElunaUtil::GetCurrTime(); uint32 oldMSTime = ElunaUtil::GetCurrTime();
lua_scripts.clear(); lua_scripts.clear();
@@ -55,23 +58,40 @@ void Eluna::Initialize()
ELUNA_LOG_DEBUG("[Eluna]: Loaded %u scripts in %u ms", uint32(lua_scripts.size() + lua_extensions.size()), ElunaUtil::GetTimeDiff(oldMSTime)); ELUNA_LOG_DEBUG("[Eluna]: Loaded %u scripts in %u ms", uint32(lua_scripts.size() + lua_extensions.size()), ElunaUtil::GetTimeDiff(oldMSTime));
initialized = true;
// Create global eluna // Create global eluna
new Eluna(); GEluna = new Eluna();
} }
void Eluna::Uninitialize() void Eluna::Uninitialize()
{ {
ASSERT(initialized);
delete GEluna; delete GEluna;
GEluna = NULL; GEluna = NULL;
lua_scripts.clear(); lua_scripts.clear();
lua_extensions.clear(); lua_extensions.clear();
initialized = false;
} }
void Eluna::ReloadEluna() void Eluna::ReloadEluna()
{ {
eWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna..."); eWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna...");
EventMgr::ProcessorSet oldProcessors;
{
EventMgr::ReadGuard lock(sEluna->eventMgr->GetLock());
oldProcessors = sEluna->eventMgr->processors;
}
Uninitialize(); Uninitialize();
Initialize(); Initialize();
{
EventMgr::WriteGuard lock(sEluna->eventMgr->GetLock());
sEluna->eventMgr->processors.insert(oldProcessors.begin(), oldProcessors.end());
}
// in multithread foreach: run scripts // in multithread foreach: run scripts
sEluna->RunScripts(); sEluna->RunScripts();
@@ -92,6 +112,8 @@ void Eluna::ReloadEluna()
Eluna::Eluna() : Eluna::Eluna() :
L(luaL_newstate()), L(luaL_newstate()),
event_level(0),
eventMgr(NULL), eventMgr(NULL),
ServerEventBindings(new EventBind<HookMgr::ServerEvents>("ServerEvents", *this)), ServerEventBindings(new EventBind<HookMgr::ServerEvents>("ServerEvents", *this)),
@@ -112,7 +134,7 @@ playerGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (player)
{ {
// open base lua // open base lua
luaL_openlibs(L); luaL_openlibs(L);
RegisterFunctions(L); RegisterFunctions(this);
// Create hidden table with weak values // Create hidden table with weak values
lua_newtable(L); lua_newtable(L);
@@ -120,7 +142,7 @@ playerGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (player)
lua_pushstring(L, "v"); lua_pushstring(L, "v");
lua_setfield(L, -2, "__mode"); lua_setfield(L, -2, "__mode");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
userdata_table = luaL_ref(L, LUA_REGISTRYINDEX); lua_setglobal(L, ELUNA_OBJECT_STORE);
// Set lua require folder paths (scripts folder structure) // Set lua require folder paths (scripts folder structure)
lua_getglobal(L, "package"); lua_getglobal(L, "package");
@@ -131,12 +153,11 @@ playerGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (player)
lua_pop(L, 1); lua_pop(L, 1);
// Replace this with map insert if making multithread version // Replace this with map insert if making multithread version
ASSERT(!Eluna::GEluna); //
Eluna::GEluna = this;
// Set event manager. Must be after setting sEluna // Set event manager. Must be after setting sEluna
eventMgr = new EventMgr(); // on multithread have a map of state pointers and here insert this pointer to the map and then save a pointer of that pointer to the EventMgr
eventMgr->globalProcessor = new ElunaEventProcessor(NULL); eventMgr = new EventMgr(&Eluna::GEluna);
} }
Eluna::~Eluna() Eluna::~Eluna()
@@ -144,9 +165,10 @@ Eluna::~Eluna()
OnLuaStateClose(); OnLuaStateClose();
delete eventMgr; delete eventMgr;
eventMgr = NULL;
// Replace this with map remove if making multithread version // Replace this with map remove if making multithread version
Eluna::GEluna = NULL; //
delete ServerEventBindings; delete ServerEventBindings;
delete PlayerEventBindings; delete PlayerEventBindings;
@@ -164,6 +186,22 @@ Eluna::~Eluna()
delete playerGossipBindings; delete playerGossipBindings;
delete BGEventBindings; delete BGEventBindings;
ServerEventBindings = NULL;
PlayerEventBindings = NULL;
GuildEventBindings = NULL;
GroupEventBindings = NULL;
VehicleEventBindings = NULL;
PacketEventBindings = NULL;
CreatureEventBindings = NULL;
CreatureGossipBindings = NULL;
GameObjectEventBindings = NULL;
GameObjectGossipBindings = NULL;
ItemEventBindings = NULL;
ItemGossipBindings = NULL;
playerGossipBindings = NULL;
BGEventBindings = NULL;
// Must close lua state after deleting stores and mgr // Must close lua state after deleting stores and mgr
lua_close(L); lua_close(L);
} }
@@ -357,20 +395,19 @@ void Eluna::RunScripts()
OnLuaStateOpen(); OnLuaStateOpen();
} }
void Eluna::RemoveRef(const void* obj) void Eluna::InvalidateObjects()
{ {
if (!sEluna) lua_getglobal(L, ELUNA_OBJECT_STORE);
return; ASSERT(lua_istable(L, -1));
lua_rawgeti(sEluna->L, LUA_REGISTRYINDEX, sEluna->userdata_table);
lua_pushfstring(sEluna->L, "%p", obj); lua_pushnil(L);
lua_gettable(sEluna->L, -2); while (lua_next(L, -2))
if (!lua_isnoneornil(sEluna->L, -1))
{ {
lua_pushfstring(sEluna->L, "%p", obj); if (ElunaObject* elunaObj = CHECKOBJ<ElunaObject>(L, -1, false))
lua_pushnil(sEluna->L); elunaObj->Invalidate();
lua_settable(sEluna->L, -4); lua_pop(L, 1);
} }
lua_pop(sEluna->L, 2); lua_pop(L, 1);
} }
void Eluna::report(lua_State* L) void Eluna::report(lua_State* L)
@@ -380,7 +417,7 @@ void Eluna::report(lua_State* L)
lua_pop(L, 1); lua_pop(L, 1);
} }
void Eluna::ExecuteCall(lua_State* L, int params, int res) void Eluna::ExecuteCall(int params, int res)
{ {
int top = lua_gettop(L); int top = lua_gettop(L);
int type = lua_type(L, top - params); int type = lua_type(L, top - params);
@@ -392,8 +429,10 @@ void Eluna::ExecuteCall(lua_State* L, int params, int res)
return; return;
} }
++event_level;
if (lua_pcall(L, params, res, 0)) if (lua_pcall(L, params, res, 0))
report(L); report(L);
--event_level;
} }
void Eluna::Push(lua_State* L) void Eluna::Push(lua_State* L)
@@ -518,9 +557,9 @@ void Eluna::Push(lua_State* L, Object const* obj)
} }
} }
static int32 CheckIntegerRange(lua_State *L, int narg, int32 min, int32 max) static int32 CheckIntegerRange(lua_State* L, int narg, int32 min, int32 max)
{ {
int64 value = luaL_checknumber(L, narg); int64 value = static_cast<int64>(luaL_checknumber(L, narg));
char error_buffer[64]; char error_buffer[64];
if (value > max) if (value > max)
@@ -535,12 +574,12 @@ static int32 CheckIntegerRange(lua_State *L, int narg, int32 min, int32 max)
return luaL_argerror(L, narg, error_buffer); return luaL_argerror(L, narg, error_buffer);
} }
return value; return static_cast<int32>(value);
} }
static uint32 CheckUnsignedRange(lua_State *L, int narg, uint32 max) static uint32 CheckUnsignedRange(lua_State* L, int narg, uint32 max)
{ {
int64 value = luaL_checknumber(L, narg); int64 value = static_cast<int64>(luaL_checknumber(L, narg));
char error_buffer[64]; char error_buffer[64];
if (value < 0) if (value < 0)
@@ -552,7 +591,7 @@ static uint32 CheckUnsignedRange(lua_State *L, int narg, uint32 max)
return luaL_argerror(L, narg, error_buffer); return luaL_argerror(L, narg, error_buffer);
} }
return value; return static_cast<uint32>(value);
} }
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg) template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg)
@@ -626,11 +665,11 @@ template<> uint64 Eluna::CHECKVAL<uint64>(lua_State* L, int narg)
return l; return l;
} }
#define TEST_OBJ(T, O, E, F)\ #define TEST_OBJ(T, O, R, F)\
{\ {\
if (!O || !O->F())\ if (!O || !O->F())\
{\ {\
if (E)\ if (R)\
{\ {\
std::string errmsg(ElunaTemplate<T>::tname);\ std::string errmsg(ElunaTemplate<T>::tname);\
errmsg += " expected";\ errmsg += " expected";\
@@ -668,6 +707,22 @@ template<> Corpse* Eluna::CHECKOBJ<Corpse>(lua_State* L, int narg, bool error)
} }
#undef TEST_OBJ #undef TEST_OBJ
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* L, int narg, bool error)
{
ElunaObject** ptrHold = static_cast<ElunaObject**>(lua_touserdata(L, narg));
if (!ptrHold)
{
if (error)
{
char buff[256];
snprintf(buff, 256, "Error fetching object index %i", narg);
luaL_argerror(L, narg, buff);
}
return NULL;
}
return *ptrHold;
}
// Saves the function reference ID given to the register type's store for given entry under the given event // Saves the function reference ID given to the register type's store for given entry under the given event
void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef)
{ {

View File

@@ -82,6 +82,7 @@ typedef VehicleInfo Vehicle;
struct lua_State; struct lua_State;
class EventMgr; class EventMgr;
class ElunaObject;
template<typename T> template<typename T>
class ElunaTemplate; class ElunaTemplate;
template<typename T> template<typename T>
@@ -97,6 +98,8 @@ struct LuaScript
std::string modulepath; std::string modulepath;
}; };
#define ELUNA_OBJECT_STORE "Eluna Object Store"
class Eluna class Eluna
{ {
private: private:
@@ -109,9 +112,10 @@ public:
static Eluna* GEluna; static Eluna* GEluna;
static bool reload; static bool reload;
static bool initialized;
lua_State* L; lua_State* L;
int userdata_table; uint32 event_level;
EventMgr* eventMgr; EventMgr* eventMgr;
@@ -147,22 +151,22 @@ public:
static void AddScriptPath(std::string filename, std::string fullpath); static void AddScriptPath(std::string filename, std::string fullpath);
static void report(lua_State*); static void report(lua_State*);
static void ExecuteCall(lua_State* L, int params, int res); void ExecuteCall(int params, int res);
void Register(uint8 reg, uint32 id, uint32 evt, int func); void Register(uint8 reg, uint32 id, uint32 evt, int func);
void RunScripts(); void RunScripts();
static void RemoveRef(const void* obj); void InvalidateObjects();
// Pushes // Pushes
static void Push(lua_State*); // nil static void Push(lua_State* L); // nil
static void Push(lua_State*, const uint64); static void Push(lua_State* L, const uint64);
static void Push(lua_State*, const int64); static void Push(lua_State* L, const int64);
static void Push(lua_State*, const uint32); static void Push(lua_State* L, const uint32);
static void Push(lua_State*, const int32); static void Push(lua_State* L, const int32);
static void Push(lua_State*, const bool); static void Push(lua_State* L, const bool);
static void Push(lua_State*, const float); static void Push(lua_State* L, const float);
static void Push(lua_State*, const double); static void Push(lua_State* L, const double);
static void Push(lua_State*, const char*); static void Push(lua_State* L, const char*);
static void Push(lua_State*, const std::string); static void Push(lua_State* L, const std::string);
template<typename T> static void Push(lua_State* L, T const* ptr) template<typename T> static void Push(lua_State* L, T const* ptr)
{ {
ElunaTemplate<T>::push(L, ptr); ElunaTemplate<T>::push(L, ptr);
@@ -185,9 +189,6 @@ public:
} }
CreatureAI* GetAI(Creature* creature); CreatureAI* GetAI(Creature* creature);
#ifdef TRINITY
GameObjectAI* GetAI(GameObject* gameObject);
#endif
/* Custom */ /* Custom */
bool OnCommand(Player* player, const char* text); bool OnCommand(Player* player, const char* text);
@@ -224,6 +225,28 @@ public:
uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature);
void OnSummoned(Creature* creature, Unit* summoner); void OnSummoned(Creature* creature, Unit* summoner);
void UpdateAI(Creature* me, const uint32 diff);
void EnterCombat(Creature* me, Unit* target);
void DamageTaken(Creature* me, Unit* attacker, uint32& damage); void JustDied(Creature* me, Unit* killer);
void KilledUnit(Creature* me, Unit* victim);
void JustSummoned(Creature* me, Creature* summon);
void SummonedCreatureDespawn(Creature* me, Creature* summon);
void MovementInform(Creature* me, uint32 type, uint32 id);
void AttackStart(Creature* me, Unit* target);
void EnterEvadeMode(Creature* me);
void AttackedBy(Creature* me, Unit* attacker);
void JustRespawned(Creature* me);
void JustReachedHome(Creature* me);
void ReceiveEmote(Creature* me, Player* player, uint32 emoteId);
void CorpseRemoved(Creature* me, uint32& respawnDelay);
void MoveInLineOfSight(Creature* me, Unit* who);
void On_Reset(Creature* me);
void SpellHit(Creature* me, Unit* caster, SpellInfo const* spell);
void SpellHitTarget(Creature* me, Unit* target, SpellInfo const* spell);
void SummonedCreatureDies(Creature* me, Creature* summon, Unit* killer);
void OwnerAttackedBy(Creature* me, Unit* attacker);
void OwnerAttacked(Creature* me, Unit* target);
/* GameObject */ /* GameObject */
bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget); bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget);
bool OnGossipHello(Player* pPlayer, GameObject* pGameObject); bool OnGossipHello(Player* pPlayer, GameObject* pGameObject);
@@ -361,7 +384,7 @@ template<> Player* Eluna::CHECKOBJ<Player>(lua_State* L, int narg, bool error);
template<> Creature* Eluna::CHECKOBJ<Creature>(lua_State* L, int narg, bool error); template<> Creature* Eluna::CHECKOBJ<Creature>(lua_State* L, int narg, bool error);
template<> GameObject* Eluna::CHECKOBJ<GameObject>(lua_State* L, int narg, bool error); template<> GameObject* Eluna::CHECKOBJ<GameObject>(lua_State* L, int narg, bool error);
template<> Corpse* Eluna::CHECKOBJ<Corpse>(lua_State* L, int narg, bool error); template<> Corpse* Eluna::CHECKOBJ<Corpse>(lua_State* L, int narg, bool error);
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* L, int narg, bool error);
#define sEluna Eluna::GEluna #define sEluna Eluna::GEluna
#endif #endif

View File

@@ -38,91 +38,93 @@ extern "C"
#include "VehicleMethods.h" #include "VehicleMethods.h"
#include "BattleGroundMethods.h" #include "BattleGroundMethods.h"
void RegisterGlobals(lua_State* L) ElunaGlobal::ElunaRegister GlobalMethods[] =
{ {
// Hooks // Hooks
lua_register(L, "RegisterPacketEvent", &LuaGlobalFunctions::RegisterPacketEvent); // RegisterPacketEvent(opcodeID, event, function) { "RegisterPacketEvent", &LuaGlobalFunctions::RegisterPacketEvent }, // RegisterPacketEvent(opcodeID, event, function)
lua_register(L, "RegisterServerEvent", &LuaGlobalFunctions::RegisterServerEvent); // RegisterServerEvent(event, function) { "RegisterServerEvent", &LuaGlobalFunctions::RegisterServerEvent }, // RegisterServerEvent(event, function)
lua_register(L, "RegisterPlayerEvent", &LuaGlobalFunctions::RegisterPlayerEvent); // RegisterPlayerEvent(event, function) { "RegisterPlayerEvent", &LuaGlobalFunctions::RegisterPlayerEvent }, // RegisterPlayerEvent(event, function)
lua_register(L, "RegisterGuildEvent", &LuaGlobalFunctions::RegisterGuildEvent); // RegisterGuildEvent(event, function) { "RegisterGuildEvent", &LuaGlobalFunctions::RegisterGuildEvent }, // RegisterGuildEvent(event, function)
lua_register(L, "RegisterGroupEvent", &LuaGlobalFunctions::RegisterGroupEvent); // RegisterGroupEvent(event, function) { "RegisterGroupEvent", &LuaGlobalFunctions::RegisterGroupEvent }, // RegisterGroupEvent(event, function)
lua_register(L, "RegisterCreatureEvent", &LuaGlobalFunctions::RegisterCreatureEvent); // RegisterCreatureEvent(entry, event, function) { "RegisterCreatureEvent", &LuaGlobalFunctions::RegisterCreatureEvent }, // RegisterCreatureEvent(entry, event, function)
lua_register(L, "RegisterCreatureGossipEvent", &LuaGlobalFunctions::RegisterCreatureGossipEvent); // RegisterCreatureGossipEvent(entry, event, function) { "RegisterCreatureGossipEvent", &LuaGlobalFunctions::RegisterCreatureGossipEvent }, // RegisterCreatureGossipEvent(entry, event, function)
lua_register(L, "RegisterGameObjectEvent", &LuaGlobalFunctions::RegisterGameObjectEvent); // RegisterGameObjectEvent(entry, event, function) { "RegisterGameObjectEvent", &LuaGlobalFunctions::RegisterGameObjectEvent }, // RegisterGameObjectEvent(entry, event, function)
lua_register(L, "RegisterGameObjectGossipEvent", &LuaGlobalFunctions::RegisterGameObjectGossipEvent); // RegisterGameObjectGossipEvent(entry, event, function) { "RegisterGameObjectGossipEvent", &LuaGlobalFunctions::RegisterGameObjectGossipEvent }, // RegisterGameObjectGossipEvent(entry, event, function)
lua_register(L, "RegisterItemEvent", &LuaGlobalFunctions::RegisterItemEvent); // RegisterItemEvent(entry, event, function) { "RegisterItemEvent", &LuaGlobalFunctions::RegisterItemEvent }, // RegisterItemEvent(entry, event, function)
lua_register(L, "RegisterItemGossipEvent", &LuaGlobalFunctions::RegisterItemGossipEvent); // RegisterItemGossipEvent(entry, event, function) { "RegisterItemGossipEvent", &LuaGlobalFunctions::RegisterItemGossipEvent }, // RegisterItemGossipEvent(entry, event, function)
lua_register(L, "RegisterPlayerGossipEvent", &LuaGlobalFunctions::RegisterPlayerGossipEvent); // RegisterPlayerGossipEvent(menu_id, event, function) { "RegisterPlayerGossipEvent", &LuaGlobalFunctions::RegisterPlayerGossipEvent }, // RegisterPlayerGossipEvent(menu_id, event, function)
lua_register(L, "RegisterBGEvent", &LuaGlobalFunctions::RegisterBGEvent); // RegisterBGEvent(event, function) { "RegisterBGEvent", &LuaGlobalFunctions::RegisterBGEvent }, // RegisterBGEvent(event, function)
// Getters // Getters
lua_register(L, "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine); { "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine },
lua_register(L, "GetCoreName", &LuaGlobalFunctions::GetCoreName); { "GetCoreName", &LuaGlobalFunctions::GetCoreName },
lua_register(L, "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion); { "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion },
lua_register(L, "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion); { "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion },
lua_register(L, "GetQuest", &LuaGlobalFunctions::GetQuest); { "GetQuest", &LuaGlobalFunctions::GetQuest },
lua_register(L, "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID); { "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID },
lua_register(L, "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName); { "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName },
lua_register(L, "GetGameTime", &LuaGlobalFunctions::GetGameTime); { "GetGameTime", &LuaGlobalFunctions::GetGameTime },
lua_register(L, "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld); { "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld },
lua_register(L, "GetPlayersInMap", &LuaGlobalFunctions::GetPlayersInMap); { "GetPlayersInMap", &LuaGlobalFunctions::GetPlayersInMap },
lua_register(L, "GetGuildByName", &LuaGlobalFunctions::GetGuildByName); { "GetGuildByName", &LuaGlobalFunctions::GetGuildByName },
lua_register(L, "GetGuildByLeaderGUID", &LuaGlobalFunctions::GetGuildByLeaderGUID); { "GetGuildByLeaderGUID", &LuaGlobalFunctions::GetGuildByLeaderGUID },
lua_register(L, "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount); { "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount },
lua_register(L, "GetPlayerGUID", &LuaGlobalFunctions::GetPlayerGUID); { "GetPlayerGUID", &LuaGlobalFunctions::GetPlayerGUID },
lua_register(L, "GetItemGUID", &LuaGlobalFunctions::GetItemGUID); { "GetItemGUID", &LuaGlobalFunctions::GetItemGUID },
lua_register(L, "GetObjectGUID", &LuaGlobalFunctions::GetObjectGUID); { "GetObjectGUID", &LuaGlobalFunctions::GetObjectGUID },
lua_register(L, "GetUnitGUID", &LuaGlobalFunctions::GetUnitGUID); { "GetUnitGUID", &LuaGlobalFunctions::GetUnitGUID },
lua_register(L, "GetGUIDLow", &LuaGlobalFunctions::GetGUIDLow); { "GetGUIDLow", &LuaGlobalFunctions::GetGUIDLow },
lua_register(L, "GetGUIDType", &LuaGlobalFunctions::GetGUIDType); { "GetGUIDType", &LuaGlobalFunctions::GetGUIDType },
lua_register(L, "GetGUIDEntry", &LuaGlobalFunctions::GetGUIDEntry); { "GetGUIDEntry", &LuaGlobalFunctions::GetGUIDEntry },
lua_register(L, "GetAreaName", &LuaGlobalFunctions::GetAreaName); { "GetAreaName", &LuaGlobalFunctions::GetAreaName },
lua_register(L, "bit_not", &LuaGlobalFunctions::bit_not); { "bit_not", &LuaGlobalFunctions::bit_not },
lua_register(L, "bit_xor", &LuaGlobalFunctions::bit_xor); { "bit_xor", &LuaGlobalFunctions::bit_xor },
lua_register(L, "bit_rshift", &LuaGlobalFunctions::bit_rshift); { "bit_rshift", &LuaGlobalFunctions::bit_rshift },
lua_register(L, "bit_lshift", &LuaGlobalFunctions::bit_lshift); { "bit_lshift", &LuaGlobalFunctions::bit_lshift },
lua_register(L, "bit_or", &LuaGlobalFunctions::bit_or); { "bit_or", &LuaGlobalFunctions::bit_or },
lua_register(L, "bit_and", &LuaGlobalFunctions::bit_and); { "bit_and", &LuaGlobalFunctions::bit_and },
lua_register(L, "GetItemLink", &LuaGlobalFunctions::GetItemLink); { "GetItemLink", &LuaGlobalFunctions::GetItemLink },
lua_register(L, "GetMapById", &LuaGlobalFunctions::GetMapById); { "GetMapById", &LuaGlobalFunctions::GetMapById },
// Boolean // Boolean
lua_register(L, "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos); { "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos },
lua_register(L, "IsEquipmentPos", &LuaGlobalFunctions::IsEquipmentPos); { "IsEquipmentPos", &LuaGlobalFunctions::IsEquipmentPos },
lua_register(L, "IsBankPos", &LuaGlobalFunctions::IsBankPos); { "IsBankPos", &LuaGlobalFunctions::IsBankPos },
lua_register(L, "IsBagPos", &LuaGlobalFunctions::IsBagPos); { "IsBagPos", &LuaGlobalFunctions::IsBagPos },
// Other // Other
lua_register(L, "ReloadEluna", &LuaGlobalFunctions::ReloadEluna); { "ReloadEluna", &LuaGlobalFunctions::ReloadEluna },
lua_register(L, "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage); { "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage },
lua_register(L, "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery); { "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery },
lua_register(L, "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute); { "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute },
lua_register(L, "CharDBQuery", &LuaGlobalFunctions::CharDBQuery); { "CharDBQuery", &LuaGlobalFunctions::CharDBQuery },
lua_register(L, "CharDBExecute", &LuaGlobalFunctions::CharDBExecute); { "CharDBExecute", &LuaGlobalFunctions::CharDBExecute },
lua_register(L, "AuthDBQuery", &LuaGlobalFunctions::AuthDBQuery); { "AuthDBQuery", &LuaGlobalFunctions::AuthDBQuery },
lua_register(L, "AuthDBExecute", &LuaGlobalFunctions::AuthDBExecute); { "AuthDBExecute", &LuaGlobalFunctions::AuthDBExecute },
lua_register(L, "CreateLuaEvent", &LuaGlobalFunctions::CreateLuaEvent); { "CreateLuaEvent", &LuaGlobalFunctions::CreateLuaEvent },
lua_register(L, "RemoveEventById", &LuaGlobalFunctions::RemoveEventById); { "RemoveEventById", &LuaGlobalFunctions::RemoveEventById },
lua_register(L, "RemoveEvents", &LuaGlobalFunctions::RemoveEvents); { "RemoveEvents", &LuaGlobalFunctions::RemoveEvents },
lua_register(L, "PerformIngameSpawn", &LuaGlobalFunctions::PerformIngameSpawn); { "PerformIngameSpawn", &LuaGlobalFunctions::PerformIngameSpawn },
lua_register(L, "CreatePacket", &LuaGlobalFunctions::CreatePacket); { "CreatePacket", &LuaGlobalFunctions::CreatePacket },
lua_register(L, "AddVendorItem", &LuaGlobalFunctions::AddVendorItem); { "AddVendorItem", &LuaGlobalFunctions::AddVendorItem },
lua_register(L, "VendorRemoveItem", &LuaGlobalFunctions::VendorRemoveItem); { "VendorRemoveItem", &LuaGlobalFunctions::VendorRemoveItem },
lua_register(L, "VendorRemoveAllItems", &LuaGlobalFunctions::VendorRemoveAllItems); { "VendorRemoveAllItems", &LuaGlobalFunctions::VendorRemoveAllItems },
lua_register(L, "Kick", &LuaGlobalFunctions::Kick); { "Kick", &LuaGlobalFunctions::Kick },
lua_register(L, "Ban", &LuaGlobalFunctions::Ban); { "Ban", &LuaGlobalFunctions::Ban },
lua_register(L, "SaveAllPlayers", &LuaGlobalFunctions::SaveAllPlayers); { "SaveAllPlayers", &LuaGlobalFunctions::SaveAllPlayers },
lua_register(L, "SendMail", &LuaGlobalFunctions::SendMail); { "SendMail", &LuaGlobalFunctions::SendMail },
lua_register(L, "AddTaxiPath", &LuaGlobalFunctions::AddTaxiPath); { "AddTaxiPath", &LuaGlobalFunctions::AddTaxiPath },
lua_register(L, "AddCorpse", &LuaGlobalFunctions::AddCorpse); { "AddCorpse", &LuaGlobalFunctions::AddCorpse },
lua_register(L, "RemoveCorpse", &LuaGlobalFunctions::RemoveCorpse); { "RemoveCorpse", &LuaGlobalFunctions::RemoveCorpse },
lua_register(L, "ConvertCorpseForPlayer", &LuaGlobalFunctions::ConvertCorpseForPlayer); { "ConvertCorpseForPlayer", &LuaGlobalFunctions::ConvertCorpseForPlayer },
lua_register(L, "RemoveOldCorpses", &LuaGlobalFunctions::RemoveOldCorpses); { "RemoveOldCorpses", &LuaGlobalFunctions::RemoveOldCorpses },
lua_register(L, "FindWeather", &LuaGlobalFunctions::FindWeather); { "FindWeather", &LuaGlobalFunctions::FindWeather },
lua_register(L, "AddWeather", &LuaGlobalFunctions::AddWeather); { "AddWeather", &LuaGlobalFunctions::AddWeather },
lua_register(L, "RemoveWeather", &LuaGlobalFunctions::RemoveWeather); { "RemoveWeather", &LuaGlobalFunctions::RemoveWeather },
lua_register(L, "SendFineWeatherToPlayer", &LuaGlobalFunctions::SendFineWeatherToPlayer); { "SendFineWeatherToPlayer", &LuaGlobalFunctions::SendFineWeatherToPlayer },
}
{ NULL, NULL },
};
ElunaRegister<Object> ObjectMethods[] = ElunaRegister<Object> ObjectMethods[] =
{ {
@@ -1246,96 +1248,99 @@ template<typename T> const char* ElunaTemplate<T>::tname = NULL;
template<typename T> bool ElunaTemplate<T>::manageMemory = false; template<typename T> bool ElunaTemplate<T>::manageMemory = false;
#if (!defined(TBC) && !defined(CLASSIC)) #if (!defined(TBC) && !defined(CLASSIC))
// fix compile error about accessing vehicle destructor // fix compile error about accessing vehicle destructor
template<> int ElunaTemplate<Vehicle>::gcT(lua_State* /*L*/) template<> int ElunaTemplate<Vehicle>::gcT(lua_State* L)
{ {
// If assert fails, should code mem management here or flag Vehicles not mem managed
ASSERT(!manageMemory); ASSERT(!manageMemory);
// Get object pointer (and check type, no error)
ElunaObject** ptrHold = static_cast<ElunaObject**>(luaL_testudata(L, -1, tname));
if (ptrHold)
{
delete *ptrHold;
}
return 0; return 0;
} }
#endif #endif
void RegisterFunctions(lua_State* L) void RegisterFunctions(Eluna* E)
{ {
RegisterGlobals(L); ElunaGlobal::SetMethods(E, GlobalMethods);
// You should add Eluna::RemoveRef(this); to all destructors for objects that are NOT mem managed (gc) by lua. ElunaTemplate<Object>::Register(E, "Object");
// Exceptions being Quest type static data structs that will never be destructed (during runtime), though they can have it as well. ElunaTemplate<Object>::SetMethods(E, ObjectMethods);
ElunaTemplate<Object>::Register(L, "Object"); ElunaTemplate<WorldObject>::Register(E, "WorldObject");
ElunaTemplate<Object>::SetMethods(L, ObjectMethods); ElunaTemplate<WorldObject>::SetMethods(E, ObjectMethods);
ElunaTemplate<WorldObject>::SetMethods(E, WorldObjectMethods);
ElunaTemplate<WorldObject>::Register(L, "WorldObject"); ElunaTemplate<Unit>::Register(E, "Unit");
ElunaTemplate<WorldObject>::SetMethods(L, ObjectMethods); ElunaTemplate<Unit>::SetMethods(E, ObjectMethods);
ElunaTemplate<WorldObject>::SetMethods(L, WorldObjectMethods); ElunaTemplate<Unit>::SetMethods(E, WorldObjectMethods);
ElunaTemplate<Unit>::SetMethods(E, UnitMethods);
ElunaTemplate<Unit>::Register(L, "Unit"); ElunaTemplate<Player>::Register(E, "Player");
ElunaTemplate<Unit>::SetMethods(L, ObjectMethods); ElunaTemplate<Player>::SetMethods(E, ObjectMethods);
ElunaTemplate<Unit>::SetMethods(L, WorldObjectMethods); ElunaTemplate<Player>::SetMethods(E, WorldObjectMethods);
ElunaTemplate<Unit>::SetMethods(L, UnitMethods); ElunaTemplate<Player>::SetMethods(E, UnitMethods);
ElunaTemplate<Player>::SetMethods(E, PlayerMethods);
ElunaTemplate<Player>::Register(L, "Player"); ElunaTemplate<Creature>::Register(E, "Creature");
ElunaTemplate<Player>::SetMethods(L, ObjectMethods); ElunaTemplate<Creature>::SetMethods(E, ObjectMethods);
ElunaTemplate<Player>::SetMethods(L, WorldObjectMethods); ElunaTemplate<Creature>::SetMethods(E, WorldObjectMethods);
ElunaTemplate<Player>::SetMethods(L, UnitMethods); ElunaTemplate<Creature>::SetMethods(E, UnitMethods);
ElunaTemplate<Player>::SetMethods(L, PlayerMethods); ElunaTemplate<Creature>::SetMethods(E, CreatureMethods);
ElunaTemplate<Creature>::Register(L, "Creature"); ElunaTemplate<GameObject>::Register(E, "GameObject");
ElunaTemplate<Creature>::SetMethods(L, ObjectMethods); ElunaTemplate<GameObject>::SetMethods(E, ObjectMethods);
ElunaTemplate<Creature>::SetMethods(L, WorldObjectMethods); ElunaTemplate<GameObject>::SetMethods(E, WorldObjectMethods);
ElunaTemplate<Creature>::SetMethods(L, UnitMethods); ElunaTemplate<GameObject>::SetMethods(E, GameObjectMethods);
ElunaTemplate<Creature>::SetMethods(L, CreatureMethods);
ElunaTemplate<GameObject>::Register(L, "GameObject"); ElunaTemplate<Corpse>::Register(E, "Corpse");
ElunaTemplate<GameObject>::SetMethods(L, ObjectMethods); ElunaTemplate<Corpse>::SetMethods(E, ObjectMethods);
ElunaTemplate<GameObject>::SetMethods(L, WorldObjectMethods); ElunaTemplate<Corpse>::SetMethods(E, WorldObjectMethods);
ElunaTemplate<GameObject>::SetMethods(L, GameObjectMethods); ElunaTemplate<Corpse>::SetMethods(E, CorpseMethods);
ElunaTemplate<Corpse>::Register(L, "Corpse"); ElunaTemplate<Item>::Register(E, "Item");
ElunaTemplate<Corpse>::SetMethods(L, ObjectMethods); ElunaTemplate<Item>::SetMethods(E, ObjectMethods);
ElunaTemplate<Corpse>::SetMethods(L, WorldObjectMethods); ElunaTemplate<Item>::SetMethods(E, ItemMethods);
ElunaTemplate<Corpse>::SetMethods(L, CorpseMethods);
ElunaTemplate<Item>::Register(L, "Item");
ElunaTemplate<Item>::SetMethods(L, ObjectMethods);
ElunaTemplate<Item>::SetMethods(L, ItemMethods);
#ifndef CLASSIC #ifndef CLASSIC
#ifndef TBC #ifndef TBC
ElunaTemplate<Vehicle>::Register(L, "Vehicle"); ElunaTemplate<Vehicle>::Register(E, "Vehicle");
ElunaTemplate<Vehicle>::SetMethods(L, VehicleMethods); ElunaTemplate<Vehicle>::SetMethods(E, VehicleMethods);
#endif #endif
#endif #endif
ElunaTemplate<Group>::Register(L, "Group"); ElunaTemplate<Group>::Register(E, "Group");
ElunaTemplate<Group>::SetMethods(L, GroupMethods); ElunaTemplate<Group>::SetMethods(E, GroupMethods);
ElunaTemplate<Guild>::Register(L, "Guild"); ElunaTemplate<Guild>::Register(E, "Guild");
ElunaTemplate<Guild>::SetMethods(L, GuildMethods); ElunaTemplate<Guild>::SetMethods(E, GuildMethods);
ElunaTemplate<Aura>::Register(L, "Aura"); ElunaTemplate<Aura>::Register(E, "Aura");
ElunaTemplate<Aura>::SetMethods(L, AuraMethods); ElunaTemplate<Aura>::SetMethods(E, AuraMethods);
ElunaTemplate<Spell>::Register(L, "Spell"); ElunaTemplate<Spell>::Register(E, "Spell");
ElunaTemplate<Spell>::SetMethods(L, SpellMethods); ElunaTemplate<Spell>::SetMethods(E, SpellMethods);
ElunaTemplate<Quest>::Register(L, "Quest"); ElunaTemplate<Quest>::Register(E, "Quest");
ElunaTemplate<Quest>::SetMethods(L, QuestMethods); ElunaTemplate<Quest>::SetMethods(E, QuestMethods);
ElunaTemplate<Map>::Register(L, "Map"); ElunaTemplate<Map>::Register(E, "Map");
ElunaTemplate<Map>::SetMethods(L, MapMethods); ElunaTemplate<Map>::SetMethods(E, MapMethods);
ElunaTemplate<Weather>::Register(L, "Weather"); ElunaTemplate<Weather>::Register(E, "Weather");
ElunaTemplate<Weather>::SetMethods(L, WeatherMethods); ElunaTemplate<Weather>::SetMethods(E, WeatherMethods);
ElunaTemplate<AuctionHouseObject>::Register(L, "AuctionHouseObject"); ElunaTemplate<AuctionHouseObject>::Register(E, "AuctionHouseObject");
ElunaTemplate<AuctionHouseObject>::SetMethods(L, AuctionMethods); ElunaTemplate<AuctionHouseObject>::SetMethods(E, AuctionMethods);
ElunaTemplate<BattleGround>::Register(L, "BattleGround"); ElunaTemplate<BattleGround>::Register(E, "BattleGround");
ElunaTemplate<BattleGround>::SetMethods(L, BattleGroundMethods); ElunaTemplate<BattleGround>::SetMethods(E, BattleGroundMethods);
ElunaTemplate<WorldPacket>::Register(L, "WorldPacket", true); ElunaTemplate<WorldPacket>::Register(E, "WorldPacket", true);
ElunaTemplate<WorldPacket>::SetMethods(L, PacketMethods); ElunaTemplate<WorldPacket>::SetMethods(E, PacketMethods);
ElunaTemplate<ElunaQuery>::Register(L, "ElunaQuery", true); ElunaTemplate<ElunaQuery>::Register(E, "ElunaQuery", true);
ElunaTemplate<ElunaQuery>::SetMethods(L, QueryMethods); ElunaTemplate<ElunaQuery>::SetMethods(E, QueryMethods);
} }

View File

@@ -16,9 +16,9 @@ namespace LuaMap
* *
* @return bool isArena * @return bool isArena
*/ */
int IsArena(lua_State* L, Map* map) int IsArena(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->IsBattleArena()); Eluna::Push(E->L, map->IsBattleArena());
return 1; return 1;
} }
#endif #endif
@@ -28,12 +28,12 @@ namespace LuaMap
* *
* @return bool isBattleGround * @return bool isBattleGround
*/ */
int IsBattleground(lua_State* L, Map* map) int IsBattleground(Eluna* E, Map* map)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, map->IsBattleGround()); Eluna::Push(E->L, map->IsBattleGround());
#else #else
Eluna::Push(L, map->IsBattleground()); Eluna::Push(E->L, map->IsBattleground());
#endif #endif
return 1; return 1;
} }
@@ -43,9 +43,9 @@ namespace LuaMap
* *
* @return bool isDungeon * @return bool isDungeon
*/ */
int IsDungeon(lua_State* L, Map* map) int IsDungeon(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->IsDungeon()); Eluna::Push(E->L, map->IsDungeon());
return 1; return 1;
} }
@@ -54,9 +54,9 @@ namespace LuaMap
* *
* @return bool isEmpty * @return bool isEmpty
*/ */
int IsEmpty(lua_State* L, Map* map) int IsEmpty(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->isEmpty()); Eluna::Push(E->L, map->isEmpty());
return 1; return 1;
} }
@@ -66,9 +66,9 @@ namespace LuaMap
* *
* @return bool isHeroic * @return bool isHeroic
*/ */
int IsHeroic(lua_State* L, Map* map) int IsHeroic(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->IsHeroic()); Eluna::Push(E->L, map->IsHeroic());
return 1; return 1;
} }
#endif #endif
@@ -78,9 +78,9 @@ namespace LuaMap
* *
* @return bool isRaid * @return bool isRaid
*/ */
int IsRaid(lua_State* L, Map* map) int IsRaid(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->IsRaid()); Eluna::Push(E->L, map->IsRaid());
return 1; return 1;
} }
@@ -89,9 +89,9 @@ namespace LuaMap
* *
* @return string mapName * @return string mapName
*/ */
int GetName(lua_State* L, Map* map) int GetName(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->GetMapName()); Eluna::Push(E->L, map->GetMapName());
return 1; return 1;
} }
@@ -102,18 +102,18 @@ namespace LuaMap
* @param float y * @param float y
* @return float z * @return float z
*/ */
int GetHeight(lua_State* L, Map* map) int GetHeight(Eluna* E, Map* map)
{ {
float x = Eluna::CHECKVAL<float>(L, 2); float x = Eluna::CHECKVAL<float>(E->L, 2);
float y = Eluna::CHECKVAL<float>(L, 3); float y = Eluna::CHECKVAL<float>(E->L, 3);
#if (defined(TBC) || defined(CLASSIC)) #if (defined(TBC) || defined(CLASSIC))
float z = map->GetHeight(x, y, MAX_HEIGHT); float z = map->GetHeight(x, y, MAX_HEIGHT);
#else #else
uint32 phasemask = Eluna::CHECKVAL<uint32>(L, 4, 1); uint32 phasemask = Eluna::CHECKVAL<uint32>(E->L, 4, 1);
float z = map->GetHeight(phasemask, x, y, MAX_HEIGHT); float z = map->GetHeight(phasemask, x, y, MAX_HEIGHT);
#endif #endif
if (z != INVALID_HEIGHT) if (z != INVALID_HEIGHT)
Eluna::Push(L, z); Eluna::Push(E->L, z);
return 1; return 1;
} }
@@ -122,12 +122,12 @@ namespace LuaMap
* *
* @return int32 difficulty * @return int32 difficulty
*/ */
int GetDifficulty(lua_State* L, Map* map) int GetDifficulty(Eluna* E, Map* map)
{ {
#ifndef CLASSIC #ifndef CLASSIC
Eluna::Push(L, map->GetDifficulty()); Eluna::Push(E->L, map->GetDifficulty());
#else #else
Eluna::Push(L, (Difficulty)0); Eluna::Push(E->L, (Difficulty)0);
#endif #endif
return 1; return 1;
} }
@@ -137,9 +137,9 @@ namespace LuaMap
* *
* @return uint32 instanceId * @return uint32 instanceId
*/ */
int GetInstanceId(lua_State* L, Map* map) int GetInstanceId(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->GetInstanceId()); Eluna::Push(E->L, map->GetInstanceId());
return 1; return 1;
} }
@@ -149,9 +149,9 @@ namespace LuaMap
* *
* @return uint32 playerCount * @return uint32 playerCount
*/ */
int GetPlayerCount(lua_State* L, Map* map) int GetPlayerCount(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->GetPlayersCountExceptGMs()); Eluna::Push(E->L, map->GetPlayersCountExceptGMs());
return 1; return 1;
} }
@@ -160,9 +160,9 @@ namespace LuaMap
* *
* @return uint32 mapId * @return uint32 mapId
*/ */
int GetMapId(lua_State* L, Map* map) int GetMapId(Eluna* E, Map* map)
{ {
Eluna::Push(L, map->GetId()); Eluna::Push(E->L, map->GetId());
return 1; return 1;
} }
@@ -174,16 +174,16 @@ namespace LuaMap
* @param float z * @param float z
* @return uint32 areaId * @return uint32 areaId
*/ */
int GetAreaId(lua_State* L, Map* map) int GetAreaId(Eluna* E, Map* map)
{ {
float x = Eluna::CHECKVAL<float>(L, 2); float x = Eluna::CHECKVAL<float>(E->L, 2);
float y = Eluna::CHECKVAL<float>(L, 3); float y = Eluna::CHECKVAL<float>(E->L, 3);
float z = Eluna::CHECKVAL<float>(L, 4); float z = Eluna::CHECKVAL<float>(E->L, 4);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, map->GetTerrain()->GetAreaId(x, y, z)); Eluna::Push(E->L, map->GetTerrain()->GetAreaId(x, y, z));
#else #else
Eluna::Push(L, map->GetAreaId(x, y, z)); Eluna::Push(E->L, map->GetAreaId(x, y, z));
#endif #endif
return 1; return 1;
} }
@@ -193,35 +193,35 @@ namespace LuaMap
* *
* @param uint64 guid * @param uint64 guid
*/ */
int GetWorldObject(lua_State* L, Map* map) int GetWorldObject(Eluna* E, Map* map)
{ {
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2); uint64 guid = Eluna::CHECKVAL<uint64>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, map->GetWorldObject(ObjectGuid(guid))); Eluna::Push(E->L, map->GetWorldObject(ObjectGuid(guid)));
#else #else
switch (GUID_HIPART(guid)) switch (GUID_HIPART(guid))
{ {
case HIGHGUID_PLAYER: case HIGHGUID_PLAYER:
Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Player*)NULL)); Eluna::Push(E->L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Player*)NULL));
break; break;
case HIGHGUID_TRANSPORT: case HIGHGUID_TRANSPORT:
case HIGHGUID_MO_TRANSPORT: case HIGHGUID_MO_TRANSPORT:
case HIGHGUID_GAMEOBJECT: case HIGHGUID_GAMEOBJECT:
Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (GameObject*)NULL)); Eluna::Push(E->L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (GameObject*)NULL));
break; break;
case HIGHGUID_VEHICLE: case HIGHGUID_VEHICLE:
case HIGHGUID_UNIT: case HIGHGUID_UNIT:
Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Creature*)NULL)); Eluna::Push(E->L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Creature*)NULL));
break; break;
case HIGHGUID_PET: case HIGHGUID_PET:
Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Pet*)NULL)); Eluna::Push(E->L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Pet*)NULL));
break; break;
case HIGHGUID_DYNAMICOBJECT: case HIGHGUID_DYNAMICOBJECT:
Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (DynamicObject*)NULL)); Eluna::Push(E->L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (DynamicObject*)NULL));
break; break;
case HIGHGUID_CORPSE: case HIGHGUID_CORPSE:
Eluna::Push(L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Corpse*)NULL)); Eluna::Push(E->L, sObjectAccessor->GetObjectInMap(ObjectGuid(guid), map, (Corpse*)NULL));
break; break;
default: default:
break; break;

View File

@@ -10,219 +10,219 @@
namespace LuaObject namespace LuaObject
{ {
/* BOOLEAN */ /* BOOLEAN */
int HasFlag(lua_State* L, Object* obj) int HasFlag(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint32 flag = Eluna::CHECKVAL<uint32>(L, 3); uint32 flag = Eluna::CHECKVAL<uint32>(E->L, 3);
Eluna::Push(L, obj->HasFlag(index, flag)); Eluna::Push(E->L, obj->HasFlag(index, flag));
return 1; return 1;
} }
int IsInWorld(lua_State* L, Object* obj) int IsInWorld(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->IsInWorld()); Eluna::Push(E->L, obj->IsInWorld());
return 1; return 1;
} }
/* GETTERS */ /* GETTERS */
int GetInt32Value(lua_State* L, Object* obj) int GetInt32Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
Eluna::Push(L, obj->GetInt32Value(index)); Eluna::Push(E->L, obj->GetInt32Value(index));
return 1; return 1;
} }
int GetUInt32Value(lua_State* L, Object* obj) int GetUInt32Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
Eluna::Push(L, obj->GetUInt32Value(index)); Eluna::Push(E->L, obj->GetUInt32Value(index));
return 1; return 1;
} }
int GetFloatValue(lua_State* L, Object* obj) int GetFloatValue(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
Eluna::Push(L, obj->GetFloatValue(index)); Eluna::Push(E->L, obj->GetFloatValue(index));
return 1; return 1;
} }
int GetByteValue(lua_State* L, Object* obj) int GetByteValue(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3); uint8 offset = Eluna::CHECKVAL<uint8>(E->L, 3);
Eluna::Push(L, obj->GetByteValue(index, offset)); Eluna::Push(E->L, obj->GetByteValue(index, offset));
return 1; return 1;
} }
int GetUInt16Value(lua_State* L, Object* obj) int GetUInt16Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3); uint8 offset = Eluna::CHECKVAL<uint8>(E->L, 3);
Eluna::Push(L, obj->GetUInt16Value(index, offset)); Eluna::Push(E->L, obj->GetUInt16Value(index, offset));
return 1; return 1;
} }
int GetScale(lua_State* L, Object* obj) int GetScale(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->GetObjectScale()); Eluna::Push(E->L, obj->GetObjectScale());
return 1; return 1;
} }
int GetEntry(lua_State* L, Object* obj) int GetEntry(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->GetEntry()); Eluna::Push(E->L, obj->GetEntry());
return 1; return 1;
} }
int GetGUID(lua_State* L, Object* obj) int GetGUID(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->GET_GUID()); Eluna::Push(E->L, obj->GET_GUID());
return 1; return 1;
} }
int GetGUIDLow(lua_State* L, Object* obj) int GetGUIDLow(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->GetGUIDLow()); Eluna::Push(E->L, obj->GetGUIDLow());
return 1; return 1;
} }
int GetTypeId(lua_State* L, Object* obj) int GetTypeId(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->GetTypeId()); Eluna::Push(E->L, obj->GetTypeId());
return 1; return 1;
} }
int GetUInt64Value(lua_State* L, Object* obj) int GetUInt64Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
obj->GetUInt64Value(index); obj->GetUInt64Value(index);
return 0; return 0;
} }
/* SETTERS */ /* SETTERS */
int SetFlag(lua_State* L, Object* obj) int SetFlag(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint32 flag = Eluna::CHECKVAL<uint32>(L, 3); uint32 flag = Eluna::CHECKVAL<uint32>(E->L, 3);
obj->SetFlag(index, flag); obj->SetFlag(index, flag);
return 0; return 0;
} }
int SetInt32Value(lua_State* L, Object* obj) int SetInt32Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
int32 value = Eluna::CHECKVAL<int32>(L, 3); int32 value = Eluna::CHECKVAL<int32>(E->L, 3);
obj->SetInt32Value(index, value); obj->SetInt32Value(index, value);
return 0; return 0;
} }
int SetUInt32Value(lua_State* L, Object* obj) int SetUInt32Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint32 value = Eluna::CHECKVAL<uint32>(L, 3); uint32 value = Eluna::CHECKVAL<uint32>(E->L, 3);
obj->SetUInt32Value(index, value); obj->SetUInt32Value(index, value);
return 0; return 0;
} }
int SetFloatValue(lua_State* L, Object* obj) int SetFloatValue(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
float value = Eluna::CHECKVAL<float>(L, 3); float value = Eluna::CHECKVAL<float>(E->L, 3);
obj->SetFloatValue(index, value); obj->SetFloatValue(index, value);
return 0; return 0;
} }
int SetByteValue(lua_State* L, Object* obj) int SetByteValue(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3); uint8 offset = Eluna::CHECKVAL<uint8>(E->L, 3);
uint8 value = Eluna::CHECKVAL<uint8>(L, 4); uint8 value = Eluna::CHECKVAL<uint8>(E->L, 4);
obj->SetByteValue(index, offset, value); obj->SetByteValue(index, offset, value);
return 0; return 0;
} }
int SetUInt16Value(lua_State* L, Object* obj) int SetUInt16Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3); uint8 offset = Eluna::CHECKVAL<uint8>(E->L, 3);
uint16 value = Eluna::CHECKVAL<uint16>(L, 4); uint16 value = Eluna::CHECKVAL<uint16>(E->L, 4);
obj->SetUInt16Value(index, offset, value); obj->SetUInt16Value(index, offset, value);
return 0; return 0;
} }
int SetInt16Value(lua_State* L, Object* obj) int SetInt16Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3); uint8 offset = Eluna::CHECKVAL<uint8>(E->L, 3);
int16 value = Eluna::CHECKVAL<int16>(L, 4); int16 value = Eluna::CHECKVAL<int16>(E->L, 4);
obj->SetInt16Value(index, offset, value); obj->SetInt16Value(index, offset, value);
return 0; return 0;
} }
int SetScale(lua_State* L, Object* obj) int SetScale(Eluna* E, Object* obj)
{ {
float size = Eluna::CHECKVAL<float>(L, 2); float size = Eluna::CHECKVAL<float>(E->L, 2);
obj->SetObjectScale(size); obj->SetObjectScale(size);
return 0; return 0;
} }
int SetUInt64Value(lua_State* L, Object* obj) int SetUInt64Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint64 value = Eluna::CHECKVAL<uint64>(L, 3); uint64 value = Eluna::CHECKVAL<uint64>(E->L, 3);
obj->SetUInt64Value(index, value); obj->SetUInt64Value(index, value);
return 0; return 0;
} }
/* OTHER */ /* OTHER */
int RemoveFlag(lua_State* L, Object* obj) int RemoveFlag(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint32 flag = Eluna::CHECKVAL<uint32>(L, 3); uint32 flag = Eluna::CHECKVAL<uint32>(E->L, 3);
obj->RemoveFlag(index, flag); obj->RemoveFlag(index, flag);
return 0; return 0;
} }
int UpdateUInt32Value(lua_State* L, Object* obj) int UpdateUInt32Value(Eluna* E, Object* obj)
{ {
uint16 index = Eluna::CHECKVAL<uint16>(L, 2); uint16 index = Eluna::CHECKVAL<uint16>(E->L, 2);
uint32 value = Eluna::CHECKVAL<uint32>(L, 3); uint32 value = Eluna::CHECKVAL<uint32>(E->L, 3);
obj->UpdateUInt32Value(index, value); obj->UpdateUInt32Value(index, value);
return 0; return 0;
} }
int ToCorpse(lua_State* L, Object* obj) int ToCorpse(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->ToCorpse()); Eluna::Push(E->L, obj->ToCorpse());
return 1; return 1;
} }
int ToGameObject(lua_State* L, Object* obj) int ToGameObject(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->ToGameObject()); Eluna::Push(E->L, obj->ToGameObject());
return 1; return 1;
} }
int ToUnit(lua_State* L, Object* obj) int ToUnit(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->ToUnit()); Eluna::Push(E->L, obj->ToUnit());
return 1; return 1;
} }
int ToCreature(lua_State* L, Object* obj) int ToCreature(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->ToCreature()); Eluna::Push(E->L, obj->ToCreature());
return 1; return 1;
} }
int ToPlayer(lua_State* L, Object* obj) int ToPlayer(Eluna* E, Object* obj)
{ {
Eluna::Push(L, obj->ToPlayer()); Eluna::Push(E->L, obj->ToPlayer());
return 1; return 1;
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -46,13 +46,13 @@ namespace LuaQuest
* @param uint32 flag : all available flags can be seen above * @param uint32 flag : all available flags can be seen above
* @return bool hasFlag * @return bool hasFlag
*/ */
int HasFlag(lua_State* L, Quest* quest) int HasFlag(Eluna* E, Quest* quest)
{ {
uint32 flag = Eluna::CHECKVAL<uint32>(L, 2); uint32 flag = Eluna::CHECKVAL<uint32>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, quest->HasQuestFlag((QuestFlags)flag)); Eluna::Push(E->L, quest->HasQuestFlag((QuestFlags)flag));
#else #else
Eluna::Push(L, quest->HasFlag(flag)); Eluna::Push(E->L, quest->HasFlag(flag));
#endif #endif
return 1; return 1;
} }
@@ -63,9 +63,9 @@ namespace LuaQuest
* *
* @return bool isDaily * @return bool isDaily
*/ */
int IsDaily(lua_State* L, Quest* quest) int IsDaily(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->IsDaily()); Eluna::Push(E->L, quest->IsDaily());
return 1; return 1;
} }
#endif #endif
@@ -75,9 +75,9 @@ namespace LuaQuest
* *
* @return bool isRepeatable * @return bool isRepeatable
*/ */
int IsRepeatable(lua_State* L, Quest* quest) int IsRepeatable(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->IsRepeatable()); Eluna::Push(E->L, quest->IsRepeatable());
return 1; return 1;
} }
@@ -86,9 +86,9 @@ namespace LuaQuest
* *
* @return uint32 entryId * @return uint32 entryId
*/ */
int GetId(lua_State* L, Quest* quest) int GetId(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetQuestId()); Eluna::Push(E->L, quest->GetQuestId());
return 1; return 1;
} }
@@ -97,9 +97,9 @@ namespace LuaQuest
* *
* @return uint32 level * @return uint32 level
*/ */
int GetLevel(lua_State* L, Quest* quest) int GetLevel(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetQuestLevel()); Eluna::Push(E->L, quest->GetQuestLevel());
return 1; return 1;
} }
@@ -108,9 +108,9 @@ namespace LuaQuest
* *
* @return uint32 minLevel * @return uint32 minLevel
*/ */
int GetMinLevel(lua_State* L, Quest* quest) int GetMinLevel(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetMinLevel()); Eluna::Push(E->L, quest->GetMinLevel());
return 1; return 1;
} }
@@ -119,9 +119,9 @@ namespace LuaQuest
* *
* @return int32 entryId * @return int32 entryId
*/ */
int GetNextQuestId(lua_State* L, Quest* quest) int GetNextQuestId(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetNextQuestId()); Eluna::Push(E->L, quest->GetNextQuestId());
return 1; return 1;
} }
@@ -130,9 +130,9 @@ namespace LuaQuest
* *
* @return int32 entryId * @return int32 entryId
*/ */
int GetPrevQuestId(lua_State* L, Quest* quest) int GetPrevQuestId(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetPrevQuestId()); Eluna::Push(E->L, quest->GetPrevQuestId());
return 1; return 1;
} }
@@ -141,9 +141,9 @@ namespace LuaQuest
* *
* @return int32 entryId * @return int32 entryId
*/ */
int GetNextQuestInChain(lua_State* L, Quest* quest) int GetNextQuestInChain(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetNextQuestInChain()); Eluna::Push(E->L, quest->GetNextQuestInChain());
return 1; return 1;
} }
@@ -152,12 +152,12 @@ namespace LuaQuest
* *
* @return uint32 flags * @return uint32 flags
*/ */
int GetFlags(lua_State* L, Quest* quest) int GetFlags(Eluna* E, Quest* quest)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, quest->GetQuestFlags()); Eluna::Push(E->L, quest->GetQuestFlags());
#else #else
Eluna::Push(L, quest->GetFlags()); Eluna::Push(E->L, quest->GetFlags());
#endif #endif
return 1; return 1;
} }
@@ -169,15 +169,15 @@ namespace LuaQuest
* *
* @return uint32 type * @return uint32 type
*/ */
int GetType(lua_State* L, Quest* quest) int GetType(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetType()); Eluna::Push(E->L, quest->GetType());
return 1; return 1;
} }
/*int GetMaxLevel(lua_State* L, Quest* quest) /*int GetMaxLevel(Eluna* E, Quest* quest)
{ {
Eluna::Push(L, quest->GetMaxLevel()); Eluna::Push(E->L, quest->GetMaxLevel());
return 1; return 1;
}*/ }*/
}; };

View File

@@ -14,9 +14,9 @@ namespace LuaSpell
* *
* @return bool isAutoRepeating * @return bool isAutoRepeating
*/ */
int IsAutoRepeat(lua_State* L, Spell* spell) int IsAutoRepeat(Eluna* E, Spell* spell)
{ {
Eluna::Push(L, spell->IsAutoRepeat()); Eluna::Push(E->L, spell->IsAutoRepeat());
return 1; return 1;
} }
@@ -25,9 +25,9 @@ namespace LuaSpell
* *
* @return [Unit] caster * @return [Unit] caster
*/ */
int GetCaster(lua_State* L, Spell* spell) int GetCaster(Eluna* E, Spell* spell)
{ {
Eluna::Push(L, spell->GetCaster()); Eluna::Push(E->L, spell->GetCaster());
return 1; return 1;
} }
@@ -36,9 +36,9 @@ namespace LuaSpell
* *
* @return int32 castTime * @return int32 castTime
*/ */
int GetCastTime(lua_State* L, Spell* spell) int GetCastTime(Eluna* E, Spell* spell)
{ {
Eluna::Push(L, spell->GetCastTime()); Eluna::Push(E->L, spell->GetCastTime());
return 1; return 1;
} }
@@ -47,9 +47,9 @@ namespace LuaSpell
* *
* @return uint32 entryId * @return uint32 entryId
*/ */
int GetEntry(lua_State* L, Spell* spell) int GetEntry(Eluna* E, Spell* spell)
{ {
Eluna::Push(L, spell->m_spellInfo->Id); Eluna::Push(E->L, spell->m_spellInfo->Id);
return 1; return 1;
} }
@@ -58,9 +58,9 @@ namespace LuaSpell
* *
* @return uint32 powerCost * @return uint32 powerCost
*/ */
int GetPowerCost(lua_State* L, Spell* spell) int GetPowerCost(Eluna* E, Spell* spell)
{ {
Eluna::Push(L, spell->GetPowerCost()); Eluna::Push(E->L, spell->GetPowerCost());
return 1; return 1;
} }
@@ -69,12 +69,12 @@ namespace LuaSpell
* *
* @return int32 duration * @return int32 duration
*/ */
int GetDuration(lua_State* L, Spell* spell) int GetDuration(Eluna* E, Spell* spell)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, GetSpellDuration(spell->m_spellInfo)); Eluna::Push(E->L, GetSpellDuration(spell->m_spellInfo));
#else #else
Eluna::Push(L, spell->GetSpellInfo()->GetDuration()); Eluna::Push(E->L, spell->GetSpellInfo()->GetDuration());
#endif #endif
return 1; return 1;
} }
@@ -86,7 +86,7 @@ namespace LuaSpell
* @return float y : y coordinate of the [Spell] * @return float y : y coordinate of the [Spell]
* @return float z : z coordinate of the [Spell] * @return float z : z coordinate of the [Spell]
*/ */
int GetTargetDest(lua_State* L, Spell* spell) int GetTargetDest(Eluna* E, Spell* spell)
{ {
#ifndef TRINITY #ifndef TRINITY
if (!(spell->m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)) if (!(spell->m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION))
@@ -99,9 +99,9 @@ namespace LuaSpell
float x, y, z; float x, y, z;
spell->m_targets.GetDstPos()->GetPosition(x, y, z); spell->m_targets.GetDstPos()->GetPosition(x, y, z);
#endif #endif
Eluna::Push(L, x); Eluna::Push(E->L, x);
Eluna::Push(L, y); Eluna::Push(E->L, y);
Eluna::Push(L, z); Eluna::Push(E->L, z);
return 3; return 3;
} }
@@ -111,28 +111,28 @@ namespace LuaSpell
* *
* @return [Object] target * @return [Object] target
*/ */
int GetTarget(lua_State* L, Spell* spell) int GetTarget(Eluna* E, Spell* spell)
{ {
#ifndef TRINITY #ifndef TRINITY
if (GameObject* target = spell->m_targets.getGOTarget()) if (GameObject* target = spell->m_targets.getGOTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (Item* target = spell->m_targets.getItemTarget()) else if (Item* target = spell->m_targets.getItemTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (Corpse* target = spell->GetCaster()->GetMap()->GetCorpse(spell->m_targets.getCorpseTargetGuid())) else if (Corpse* target = spell->GetCaster()->GetMap()->GetCorpse(spell->m_targets.getCorpseTargetGuid()))
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (Unit* target = spell->m_targets.getUnitTarget()) else if (Unit* target = spell->m_targets.getUnitTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
#else #else
if (GameObject* target = spell->m_targets.GetGOTarget()) if (GameObject* target = spell->m_targets.GetGOTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (Item* target = spell->m_targets.GetItemTarget()) else if (Item* target = spell->m_targets.GetItemTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (Corpse* target = spell->m_targets.GetCorpseTarget()) else if (Corpse* target = spell->m_targets.GetCorpseTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (Unit* target = spell->m_targets.GetUnitTarget()) else if (Unit* target = spell->m_targets.GetUnitTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
else if (WorldObject* target = spell->m_targets.GetObjectTarget()) else if (WorldObject* target = spell->m_targets.GetObjectTarget())
Eluna::Push(L, target); Eluna::Push(E->L, target);
#endif #endif
return 1; return 1;
} }
@@ -142,9 +142,9 @@ namespace LuaSpell
* *
* @param bool repeat : set variable to 'true' for spell to automatically repeat * @param bool repeat : set variable to 'true' for spell to automatically repeat
*/ */
int SetAutoRepeat(lua_State* L, Spell* spell) int SetAutoRepeat(Eluna* E, Spell* spell)
{ {
bool repeat = Eluna::CHECKVAL<bool>(L, 2); bool repeat = Eluna::CHECKVAL<bool>(E->L, 2);
spell->SetAutoRepeat(repeat); spell->SetAutoRepeat(repeat);
return 0; return 0;
} }
@@ -154,9 +154,9 @@ namespace LuaSpell
* *
* @param bool skipCheck = false : skips initial checks to see if the [Spell] can be casted or not, this is optional * @param bool skipCheck = false : skips initial checks to see if the [Spell] can be casted or not, this is optional
*/ */
int Cast(lua_State* L, Spell* spell) int Cast(Eluna* E, Spell* spell)
{ {
bool skipCheck = Eluna::CHECKVAL<bool>(L, 2, false); bool skipCheck = Eluna::CHECKVAL<bool>(E->L, 2, false);
spell->cast(skipCheck); spell->cast(skipCheck);
return 0; return 0;
} }
@@ -165,7 +165,7 @@ namespace LuaSpell
* Cancels the [Spell]. * Cancels the [Spell].
* *
*/ */
int Cancel(lua_State* /*L*/, Spell* spell) int Cancel(Eluna* /*E*/, Spell* spell)
{ {
spell->cancel(); spell->cancel();
return 0; return 0;
@@ -175,7 +175,7 @@ namespace LuaSpell
* Finishes the [Spell]. * Finishes the [Spell].
* *
*/ */
int Finish(lua_State* /*L*/, Spell* spell) int Finish(Eluna* /*E*/, Spell* spell)
{ {
spell->finish(); spell->finish();
return 0; return 0;

File diff suppressed because it is too large Load Diff

View File

@@ -12,50 +12,50 @@
namespace LuaVehicle namespace LuaVehicle
{ {
/* BOOLEAN */ /* BOOLEAN */
int IsOnBoard(lua_State* L, Vehicle* vehicle) int IsOnBoard(Eluna* E, Vehicle* vehicle)
{ {
Unit* passenger = Eluna::CHECKOBJ<Unit>(L, 2); Unit* passenger = Eluna::CHECKOBJ<Unit>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, vehicle->HasOnBoard(passenger)); Eluna::Push(E->L, vehicle->HasOnBoard(passenger));
#else #else
Eluna::Push(L, passenger->IsOnVehicle(vehicle->GetBase())); Eluna::Push(E->L, passenger->IsOnVehicle(vehicle->GetBase()));
#endif #endif
return 1; return 1;
} }
/* GETTERS */ /* GETTERS */
int GetOwner(lua_State* L, Vehicle* vehicle) int GetOwner(Eluna* E, Vehicle* vehicle)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, vehicle->GetOwner()); Eluna::Push(E->L, vehicle->GetOwner());
#else #else
Eluna::Push(L, vehicle->GetBase()); Eluna::Push(E->L, vehicle->GetBase());
#endif #endif
return 1; return 1;
} }
int GetEntry(lua_State* L, Vehicle* vehicle) int GetEntry(Eluna* E, Vehicle* vehicle)
{ {
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, vehicle->GetVehicleEntry()->m_ID); Eluna::Push(E->L, vehicle->GetVehicleEntry()->m_ID);
#else #else
Eluna::Push(L, vehicle->GetVehicleInfo()->m_ID); Eluna::Push(E->L, vehicle->GetVehicleInfo()->m_ID);
#endif #endif
return 1; return 1;
} }
int GetPassenger(lua_State* L, Vehicle* vehicle) int GetPassenger(Eluna* E, Vehicle* vehicle)
{ {
int8 seatId = Eluna::CHECKVAL<int8>(L, 2); int8 seatId = Eluna::CHECKVAL<int8>(E->L, 2);
Eluna::Push(L, vehicle->GetPassenger(seatId)); Eluna::Push(E->L, vehicle->GetPassenger(seatId));
return 1; return 1;
} }
/* OTHER */ /* OTHER */
int AddPassenger(lua_State* L, Vehicle* vehicle) int AddPassenger(Eluna* E, Vehicle* vehicle)
{ {
Unit* passenger = Eluna::CHECKOBJ<Unit>(L, 2); Unit* passenger = Eluna::CHECKOBJ<Unit>(E->L, 2);
int8 seatId = Eluna::CHECKVAL<int8>(L, 3); int8 seatId = Eluna::CHECKVAL<int8>(E->L, 3);
#ifndef TRINITY #ifndef TRINITY
if (vehicle->CanBoard(passenger)) if (vehicle->CanBoard(passenger))
vehicle->Board(passenger, seatId); vehicle->Board(passenger, seatId);
@@ -65,9 +65,9 @@ namespace LuaVehicle
return 0; return 0;
} }
int RemovePassenger(lua_State* L, Vehicle* vehicle) int RemovePassenger(Eluna* E, Vehicle* vehicle)
{ {
Unit* passenger = Eluna::CHECKOBJ<Unit>(L, 2); Unit* passenger = Eluna::CHECKOBJ<Unit>(E->L, 2);
#ifndef TRINITY #ifndef TRINITY
vehicle->UnBoard(passenger, false); vehicle->UnBoard(passenger, false);
#else #else

View File

@@ -14,9 +14,9 @@ namespace LuaWeather
* *
* @return uint32 zoneId * @return uint32 zoneId
*/ */
int GetZoneId(lua_State* L, Weather* weather) int GetZoneId(Eluna* E, Weather* weather)
{ {
Eluna::Push(L, weather->GetZone()); Eluna::Push(E->L, weather->GetZone());
return 1; return 1;
} }
@@ -38,10 +38,10 @@ namespace LuaWeather
* @param WeatherType type : the [WeatherType], see above available weather types * @param WeatherType type : the [WeatherType], see above available weather types
* @param float grade : the intensity/grade of the [Weather], ranges from 0 to 1 * @param float grade : the intensity/grade of the [Weather], ranges from 0 to 1
*/ */
int SetWeather(lua_State* L, Weather* weather) int SetWeather(Eluna* E, Weather* weather)
{ {
uint32 weatherType = Eluna::CHECKVAL<uint32>(L, 2); uint32 weatherType = Eluna::CHECKVAL<uint32>(E->L, 2);
float grade = Eluna::CHECKVAL<float>(L, 3); float grade = Eluna::CHECKVAL<float>(E->L, 3);
weather->SetWeather((WeatherType)weatherType, grade); weather->SetWeather((WeatherType)weatherType, grade);
return 0; return 0;
@@ -52,9 +52,9 @@ namespace LuaWeather
* *
* @param [Player] player * @param [Player] player
*/ */
int SendWeatherUpdateToPlayer(lua_State* L, Weather* weather) int SendWeatherUpdateToPlayer(Eluna* E, Weather* weather)
{ {
Player* player = Eluna::CHECKOBJ<Player>(L, 2); Player* player = Eluna::CHECKOBJ<Player>(E->L, 2);
weather->SendWeatherUpdateToPlayer(player); weather->SendWeatherUpdateToPlayer(player);
return 0; return 0;
@@ -70,9 +70,9 @@ namespace LuaWeather
* *
* @return bool changed : returns 'true' if [Weather] changed * @return bool changed : returns 'true' if [Weather] changed
*/ */
int Regenerate(lua_State* L, Weather* weather) int Regenerate(Eluna* E, Weather* weather)
{ {
Eluna::Push(L, weather->ReGenerate()); Eluna::Push(E->L, weather->ReGenerate());
return 1; return 1;
} }
@@ -81,9 +81,9 @@ namespace LuaWeather
* *
* @param bool changed : returns 'true' if weather changed for any [Player] in the zone, 'false' if no [Player] is within the zone * @param bool changed : returns 'true' if weather changed for any [Player] in the zone, 'false' if no [Player] is within the zone
*/ */
int UpdateWeather(lua_State* L, Weather* weather) int UpdateWeather(Eluna* E, Weather* weather)
{ {
Eluna::Push(L, weather->UpdateWeather()); Eluna::Push(E->L, weather->UpdateWeather());
return 1; return 1;
} }
}; };

View File

@@ -14,9 +14,9 @@ namespace LuaWorldObject
* *
* @return string name * @return string name
*/ */
int GetName(lua_State* L, WorldObject* obj) int GetName(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetName()); Eluna::Push(E->L, obj->GetName());
return 1; return 1;
} }
@@ -25,9 +25,9 @@ namespace LuaWorldObject
* *
* @return [Map] mapObject * @return [Map] mapObject
*/ */
int GetMap(lua_State* L, WorldObject* obj) int GetMap(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetMap()); Eluna::Push(E->L, obj->GetMap());
return 1; return 1;
} }
@@ -37,9 +37,9 @@ namespace LuaWorldObject
* *
* @return uint32 phase * @return uint32 phase
*/ */
int GetPhaseMask(lua_State* L, WorldObject* obj) int GetPhaseMask(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetPhaseMask()); Eluna::Push(E->L, obj->GetPhaseMask());
return 1; return 1;
} }
#endif #endif
@@ -49,9 +49,9 @@ namespace LuaWorldObject
* *
* @return uint32 instanceId * @return uint32 instanceId
*/ */
int GetInstanceId(lua_State* L, WorldObject* obj) int GetInstanceId(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetInstanceId()); Eluna::Push(E->L, obj->GetInstanceId());
return 1; return 1;
} }
@@ -60,9 +60,9 @@ namespace LuaWorldObject
* *
* @return uint32 areaId * @return uint32 areaId
*/ */
int GetAreaId(lua_State* L, WorldObject* obj) int GetAreaId(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetAreaId()); Eluna::Push(E->L, obj->GetAreaId());
return 1; return 1;
} }
@@ -71,9 +71,9 @@ namespace LuaWorldObject
* *
* @return uint32 zoneId * @return uint32 zoneId
*/ */
int GetZoneId(lua_State* L, WorldObject* obj) int GetZoneId(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetZoneId()); Eluna::Push(E->L, obj->GetZoneId());
return 1; return 1;
} }
@@ -82,9 +82,9 @@ namespace LuaWorldObject
* *
* @return uint32 mapId * @return uint32 mapId
*/ */
int GetMapId(lua_State* L, WorldObject* obj) int GetMapId(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetMapId()); Eluna::Push(E->L, obj->GetMapId());
return 1; return 1;
} }
@@ -93,9 +93,9 @@ namespace LuaWorldObject
* *
* @return float x * @return float x
*/ */
int GetX(lua_State* L, WorldObject* obj) int GetX(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetPositionX()); Eluna::Push(E->L, obj->GetPositionX());
return 1; return 1;
} }
@@ -104,9 +104,9 @@ namespace LuaWorldObject
* *
* @return float y * @return float y
*/ */
int GetY(lua_State* L, WorldObject* obj) int GetY(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetPositionY()); Eluna::Push(E->L, obj->GetPositionY());
return 1; return 1;
} }
@@ -115,9 +115,9 @@ namespace LuaWorldObject
* *
* @return float z * @return float z
*/ */
int GetZ(lua_State* L, WorldObject* obj) int GetZ(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetPositionZ()); Eluna::Push(E->L, obj->GetPositionZ());
return 1; return 1;
} }
@@ -126,9 +126,9 @@ namespace LuaWorldObject
* *
* @return float orientation / facing * @return float orientation / facing
*/ */
int GetO(lua_State* L, WorldObject* obj) int GetO(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetOrientation()); Eluna::Push(E->L, obj->GetOrientation());
return 1; return 1;
} }
@@ -140,12 +140,12 @@ namespace LuaWorldObject
* @return float z : z coordinate (height) of the [WorldObject] * @return float z : z coordinate (height) of the [WorldObject]
* @return float o : facing / orientation of the [WorldObject] * @return float o : facing / orientation of the [WorldObject]
*/ */
int GetLocation(lua_State* L, WorldObject* obj) int GetLocation(Eluna* E, WorldObject* obj)
{ {
Eluna::Push(L, obj->GetPositionX()); Eluna::Push(E->L, obj->GetPositionX());
Eluna::Push(L, obj->GetPositionY()); Eluna::Push(E->L, obj->GetPositionY());
Eluna::Push(L, obj->GetPositionZ()); Eluna::Push(E->L, obj->GetPositionZ());
Eluna::Push(L, obj->GetOrientation()); Eluna::Push(E->L, obj->GetOrientation());
return 4; return 4;
} }
@@ -156,9 +156,9 @@ namespace LuaWorldObject
* *
* @return [Player] nearestPlayer * @return [Player] nearestPlayer
*/ */
int GetNearestPlayer(lua_State* L, WorldObject* obj) int GetNearestPlayer(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
Unit* target = NULL; Unit* target = NULL;
ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER); ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER);
@@ -170,7 +170,7 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
Eluna::Push(L, target); Eluna::Push(E->L, target);
return 1; return 1;
} }
@@ -182,10 +182,10 @@ namespace LuaWorldObject
* *
* @return [GameObject] nearestGameObject * @return [GameObject] nearestGameObject
*/ */
int GetNearestGameObject(lua_State* L, WorldObject* obj) int GetNearestGameObject(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 3, 0);
GameObject* target = NULL; GameObject* target = NULL;
ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_GAMEOBJECT, entry); ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_GAMEOBJECT, entry);
@@ -197,7 +197,7 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
Eluna::Push(L, target); Eluna::Push(E->L, target);
return 1; return 1;
} }
@@ -209,10 +209,10 @@ namespace LuaWorldObject
* *
* @return [Creature] nearestCreature * @return [Creature] nearestCreature
*/ */
int GetNearestCreature(lua_State* L, WorldObject* obj) int GetNearestCreature(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 3, 0);
Creature* target = NULL; Creature* target = NULL;
ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry); ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry);
@@ -224,7 +224,7 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
Eluna::Push(L, target); Eluna::Push(E->L, target);
return 1; return 1;
} }
@@ -235,9 +235,9 @@ namespace LuaWorldObject
* *
* @return table playersInRange : table of [Player]s * @return table playersInRange : table of [Player]s
*/ */
int GetPlayersInRange(lua_State* L, WorldObject* obj) int GetPlayersInRange(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
std::list<Player*> list; std::list<Player*> list;
ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER); ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER);
@@ -249,18 +249,18 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
for (std::list<Player*>::const_iterator it = list.begin(); it != list.end(); ++it) for (std::list<Player*>::const_iterator it = list.begin(); it != list.end(); ++it)
{ {
Eluna::Push(L, ++i); Eluna::Push(E->L, ++i);
Eluna::Push(L, *it); Eluna::Push(E->L, *it);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); lua_settop(E->L, tbl);
return 1; return 1;
} }
@@ -272,10 +272,10 @@ namespace LuaWorldObject
* *
* @return table creaturesInRange : table of [Creature]s * @return table creaturesInRange : table of [Creature]s
*/ */
int GetCreaturesInRange(lua_State* L, WorldObject* obj) int GetCreaturesInRange(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 3, 0);
std::list<Creature*> list; std::list<Creature*> list;
ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry); ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry);
@@ -287,18 +287,18 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
for (std::list<Creature*>::const_iterator it = list.begin(); it != list.end(); ++it) for (std::list<Creature*>::const_iterator it = list.begin(); it != list.end(); ++it)
{ {
Eluna::Push(L, ++i); Eluna::Push(E->L, ++i);
Eluna::Push(L, *it); Eluna::Push(E->L, *it);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); lua_settop(E->L, tbl);
return 1; return 1;
} }
@@ -310,10 +310,10 @@ namespace LuaWorldObject
* *
* @return table gameObjectsInRange : table of [GameObject]s * @return table gameObjectsInRange : table of [GameObject]s
*/ */
int GetGameObjectsInRange(lua_State* L, WorldObject* obj) int GetGameObjectsInRange(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
uint32 entry = Eluna::CHECKVAL<uint32>(L, 3, 0); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 3, 0);
std::list<GameObject*> list; std::list<GameObject*> list;
ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_GAMEOBJECT, entry); ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_GAMEOBJECT, entry);
@@ -325,18 +325,18 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
for (std::list<GameObject*>::const_iterator it = list.begin(); it != list.end(); ++it) for (std::list<GameObject*>::const_iterator it = list.begin(); it != list.end(); ++it)
{ {
Eluna::Push(L, ++i); Eluna::Push(E->L, ++i);
Eluna::Push(L, *it); Eluna::Push(E->L, *it);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); lua_settop(E->L, tbl);
return 1; return 1;
} }
@@ -351,12 +351,12 @@ namespace LuaWorldObject
* *
* @return [WorldObject] worldObject * @return [WorldObject] worldObject
*/ */
int GetNearObject(lua_State* L, WorldObject* obj) int GetNearObject(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
uint16 type = Eluna::CHECKVAL<uint16>(L, 3, 0); // TypeMask uint16 type = Eluna::CHECKVAL<uint16>(E->L, 3, 0); // TypeMask
uint32 entry = Eluna::CHECKVAL<uint32>(L, 4, 0); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 4, 0);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 5, 0); // 0 none, 1 hostile, 2 friendly uint32 hostile = Eluna::CHECKVAL<uint32>(E->L, 5, 0); // 0 none, 1 hostile, 2 friendly
float x, y, z; float x, y, z;
obj->GetPosition(x, y, z); obj->GetPosition(x, y, z);
@@ -371,7 +371,7 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
Eluna::Push(L, target); Eluna::Push(E->L, target);
return 1; return 1;
} }
@@ -386,12 +386,12 @@ namespace LuaWorldObject
* *
* @return table worldObjectList : table of [WorldObject]s * @return table worldObjectList : table of [WorldObject]s
*/ */
int GetNearObjects(lua_State* L, WorldObject* obj) int GetNearObjects(Eluna* E, WorldObject* obj)
{ {
float range = Eluna::CHECKVAL<float>(L, 2, SIZE_OF_GRIDS); float range = Eluna::CHECKVAL<float>(E->L, 2, SIZE_OF_GRIDS);
uint16 type = Eluna::CHECKVAL<uint16>(L, 3, 0); // TypeMask uint16 type = Eluna::CHECKVAL<uint16>(E->L, 3, 0); // TypeMask
uint32 entry = Eluna::CHECKVAL<uint32>(L, 4, 0); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 4, 0);
uint32 hostile = Eluna::CHECKVAL<uint32>(L, 5, 0); // 0 none, 1 hostile, 2 friendly uint32 hostile = Eluna::CHECKVAL<uint32>(E->L, 5, 0); // 0 none, 1 hostile, 2 friendly
float x, y, z; float x, y, z;
obj->GetPosition(x, y, z); obj->GetPosition(x, y, z);
@@ -406,18 +406,18 @@ namespace LuaWorldObject
obj->VisitNearbyObject(range, searcher); obj->VisitNearbyObject(range, searcher);
#endif #endif
lua_newtable(L); lua_newtable(E->L);
int tbl = lua_gettop(L); int tbl = lua_gettop(E->L);
uint32 i = 0; uint32 i = 0;
for (std::list<WorldObject*>::const_iterator it = list.begin(); it != list.end(); ++it) for (std::list<WorldObject*>::const_iterator it = list.begin(); it != list.end(); ++it)
{ {
Eluna::Push(L, ++i); Eluna::Push(E->L, ++i);
Eluna::Push(L, *it); Eluna::Push(E->L, *it);
lua_settable(L, tbl); lua_settable(E->L, tbl);
} }
lua_settop(L, tbl); lua_settop(E->L, tbl);
return 1; return 1;
} }
@@ -434,17 +434,17 @@ namespace LuaWorldObject
* *
* @return float dist : the distance in yards * @return float dist : the distance in yards
*/ */
int GetDistance(lua_State* L, WorldObject* obj) int GetDistance(Eluna* E, WorldObject* obj)
{ {
WorldObject* target = Eluna::CHECKOBJ<WorldObject>(L, 2, false); WorldObject* target = Eluna::CHECKOBJ<WorldObject>(E->L, 2, false);
if (target && target->IsInWorld()) if (target && target->IsInWorld())
Eluna::Push(L, obj->GetDistance(target)); Eluna::Push(E->L, obj->GetDistance(target));
else else
{ {
float X = Eluna::CHECKVAL<float>(L, 2); float X = Eluna::CHECKVAL<float>(E->L, 2);
float Y = Eluna::CHECKVAL<float>(L, 3); float Y = Eluna::CHECKVAL<float>(E->L, 3);
float Z = Eluna::CHECKVAL<float>(L, 4); float Z = Eluna::CHECKVAL<float>(E->L, 4);
Eluna::Push(L, obj->GetDistance(X, Y, Z)); Eluna::Push(E->L, obj->GetDistance(X, Y, Z));
} }
return 1; return 1;
} }
@@ -459,17 +459,17 @@ namespace LuaWorldObject
* @return float y * @return float y
* @return float z * @return float z
*/ */
int GetRelativePoint(lua_State* L, WorldObject* obj) int GetRelativePoint(Eluna* E, WorldObject* obj)
{ {
float dist = Eluna::CHECKVAL<float>(L, 2); float dist = Eluna::CHECKVAL<float>(E->L, 2);
float rad = Eluna::CHECKVAL<float>(L, 3); float rad = Eluna::CHECKVAL<float>(E->L, 3);
float x, y, z; float x, y, z;
obj->GetClosePoint(x, y, z, 0.0f, dist, rad); obj->GetClosePoint(x, y, z, 0.0f, dist, rad);
Eluna::Push(L, x); Eluna::Push(E->L, x);
Eluna::Push(L, y); Eluna::Push(E->L, y);
Eluna::Push(L, z); Eluna::Push(E->L, z);
return 3; return 3;
} }
@@ -486,17 +486,17 @@ namespace LuaWorldObject
* *
* @return float angle : angle in radians in range 0..2*pi * @return float angle : angle in radians in range 0..2*pi
*/ */
int GetAngle(lua_State* L, WorldObject* obj) int GetAngle(Eluna* E, WorldObject* obj)
{ {
WorldObject* target = Eluna::CHECKOBJ<WorldObject>(L, 2, false); WorldObject* target = Eluna::CHECKOBJ<WorldObject>(E->L, 2, false);
if (target && target->IsInWorld()) if (target && target->IsInWorld())
Eluna::Push(L, obj->GetAngle(target)); Eluna::Push(E->L, obj->GetAngle(target));
else else
{ {
float x = Eluna::CHECKVAL<float>(L, 2); float x = Eluna::CHECKVAL<float>(E->L, 2);
float y = Eluna::CHECKVAL<float>(L, 3); float y = Eluna::CHECKVAL<float>(E->L, 3);
Eluna::Push(L, obj->GetAngle(x, y)); Eluna::Push(E->L, obj->GetAngle(x, y));
} }
return 1; return 1;
} }
@@ -506,9 +506,9 @@ namespace LuaWorldObject
* *
* @param [WorldPacket] packet * @param [WorldPacket] packet
*/ */
int SendPacket(lua_State* L, WorldObject* obj) int SendPacket(Eluna* E, WorldObject* obj)
{ {
WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(L, 2); WorldPacket* data = Eluna::CHECKOBJ<WorldPacket>(E->L, 2);
obj->SendMessageToSet(data, true); obj->SendMessageToSet(data, true);
return 0; return 0;
} }
@@ -524,18 +524,18 @@ namespace LuaWorldObject
* @param uint32 respawnDelay = 30 : respawn time in seconds * @param uint32 respawnDelay = 30 : respawn time in seconds
* @return [GameObject] gameObject * @return [GameObject] gameObject
*/ */
int SummonGameObject(lua_State* L, WorldObject* obj) int SummonGameObject(Eluna* E, WorldObject* obj)
{ {
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 2);
float x = Eluna::CHECKVAL<float>(L, 3); float x = Eluna::CHECKVAL<float>(E->L, 3);
float y = Eluna::CHECKVAL<float>(L, 4); float y = Eluna::CHECKVAL<float>(E->L, 4);
float z = Eluna::CHECKVAL<float>(L, 5); float z = Eluna::CHECKVAL<float>(E->L, 5);
float o = Eluna::CHECKVAL<float>(L, 6); float o = Eluna::CHECKVAL<float>(E->L, 6);
uint32 respawnDelay = Eluna::CHECKVAL<uint32>(L, 7, 30); uint32 respawnDelay = Eluna::CHECKVAL<uint32>(E->L, 7, 30);
#ifndef TRINITY #ifndef TRINITY
Eluna::Push(L, obj->SummonGameObject(entry, x, y, z, o, respawnDelay)); Eluna::Push(E->L, obj->SummonGameObject(entry, x, y, z, o, respawnDelay));
#else #else
Eluna::Push(L, obj->SummonGameObject(entry, x, y, z, o, 0, 0, 0, 0, respawnDelay)); Eluna::Push(E->L, obj->SummonGameObject(entry, x, y, z, o, 0, 0, 0, 0, respawnDelay));
#endif #endif
return 1; return 1;
} }
@@ -552,15 +552,15 @@ namespace LuaWorldObject
* @param uint32 despawnTimer : despawn time in seconds * @param uint32 despawnTimer : despawn time in seconds
* @return [Creature] spawnedCreature * @return [Creature] spawnedCreature
*/ */
int SpawnCreature(lua_State* L, WorldObject* obj) int SpawnCreature(Eluna* E, WorldObject* obj)
{ {
uint32 entry = Eluna::CHECKVAL<uint32>(L, 2); uint32 entry = Eluna::CHECKVAL<uint32>(E->L, 2);
float x = Eluna::CHECKVAL<float>(L, 3); float x = Eluna::CHECKVAL<float>(E->L, 3);
float y = Eluna::CHECKVAL<float>(L, 4); float y = Eluna::CHECKVAL<float>(E->L, 4);
float z = Eluna::CHECKVAL<float>(L, 5); float z = Eluna::CHECKVAL<float>(E->L, 5);
float o = Eluna::CHECKVAL<float>(L, 6); float o = Eluna::CHECKVAL<float>(E->L, 6);
uint32 spawnType = Eluna::CHECKVAL<uint32>(L, 7, 8); uint32 spawnType = Eluna::CHECKVAL<uint32>(E->L, 7, 8);
uint32 despawnTimer = Eluna::CHECKVAL<uint32>(L, 8, 0); uint32 despawnTimer = Eluna::CHECKVAL<uint32>(E->L, 8, 0);
TempSummonType type; TempSummonType type;
switch (spawnType) switch (spawnType)
@@ -602,9 +602,9 @@ namespace LuaWorldObject
break; break;
#endif #endif
default: default:
return luaL_argerror(L, 7, "valid SpawnType expected"); return luaL_argerror(E->L, 7, "valid SpawnType expected");
} }
Eluna::Push(L, obj->SummonCreature(entry, x, y, z, o, type, despawnTimer)); Eluna::Push(E->L, obj->SummonCreature(entry, x, y, z, o, type, despawnTimer));
return 1; return 1;
} }
@@ -621,18 +621,18 @@ namespace LuaWorldObject
* @param uint32 repeats : how many times for the event to repeat, 0 is infinite * @param uint32 repeats : how many times for the event to repeat, 0 is infinite
* @return int eventId : unique ID for the timed event used to cancel it or nil * @return int eventId : unique ID for the timed event used to cancel it or nil
*/ */
int RegisterEvent(lua_State* L, WorldObject* obj) int RegisterEvent(Eluna* E, WorldObject* obj)
{ {
luaL_checktype(L, 2, LUA_TFUNCTION); luaL_checktype(E->L, 2, LUA_TFUNCTION);
uint32 delay = Eluna::CHECKVAL<uint32>(L, 3); uint32 delay = Eluna::CHECKVAL<uint32>(E->L, 3);
uint32 repeats = Eluna::CHECKVAL<uint32>(L, 4); uint32 repeats = Eluna::CHECKVAL<uint32>(E->L, 4);
lua_pushvalue(L, 2); lua_pushvalue(E->L, 2);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX);
if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF) if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF)
{ {
obj->elunaEvents->AddEvent(functionRef, delay, repeats); obj->elunaEvents->AddEvent(functionRef, delay, repeats);
Eluna::Push(L, functionRef); Eluna::Push(E->L, functionRef);
} }
return 1; return 1;
} }
@@ -642,9 +642,9 @@ namespace LuaWorldObject
* *
* @param int eventId : event Id to remove * @param int eventId : event Id to remove
*/ */
int RemoveEventById(lua_State* L, WorldObject* obj) int RemoveEventById(Eluna* E, WorldObject* obj)
{ {
int eventId = Eluna::CHECKVAL<int>(L, 2); int eventId = Eluna::CHECKVAL<int>(E->L, 2);
obj->elunaEvents->RemoveEvent(eventId); obj->elunaEvents->RemoveEvent(eventId);
return 0; return 0;
} }
@@ -653,7 +653,7 @@ namespace LuaWorldObject
* Removes all timed events from a [WorldObject] * Removes all timed events from a [WorldObject]
* *
*/ */
int RemoveEvents(lua_State* /*L*/, WorldObject* obj) int RemoveEvents(Eluna* /*E*/, WorldObject* obj)
{ {
obj->elunaEvents->RemoveEvents(); obj->elunaEvents->RemoveEvents();
return 0; return 0;
@@ -671,18 +671,18 @@ namespace LuaWorldObject
* @param float z * @param float z
* @return bool isInLoS * @return bool isInLoS
*/ */
int IsWithinLoS(lua_State* L, WorldObject* obj) int IsWithinLoS(Eluna* E, WorldObject* obj)
{ {
WorldObject* target = Eluna::CHECKOBJ<WorldObject>(L, 2, false); WorldObject* target = Eluna::CHECKOBJ<WorldObject>(E->L, 2, false);
if (target) if (target)
Eluna::Push(L, obj->IsWithinLOSInMap(target)); Eluna::Push(E->L, obj->IsWithinLOSInMap(target));
else else
{ {
float x = Eluna::CHECKVAL<float>(L, 2); float x = Eluna::CHECKVAL<float>(E->L, 2);
float y = Eluna::CHECKVAL<float>(L, 3); float y = Eluna::CHECKVAL<float>(E->L, 3);
float z = Eluna::CHECKVAL<float>(L, 4); float z = Eluna::CHECKVAL<float>(E->L, 4);
Eluna::Push(L, obj->IsWithinLOS(x, y, z)); Eluna::Push(E->L, obj->IsWithinLOS(x, y, z));
} }
return 1; return 1;

View File

@@ -14,9 +14,9 @@ namespace LuaPacket
* *
* @return uint16 opcode * @return uint16 opcode
*/ */
int GetOpcode(lua_State* L, WorldPacket* packet) int GetOpcode(Eluna* E, WorldPacket* packet)
{ {
Eluna::Push(L, packet->GetOpcode()); Eluna::Push(E->L, packet->GetOpcode());
return 1; return 1;
} }
@@ -25,9 +25,9 @@ namespace LuaPacket
* *
* @return uint32 size : size of [WorldPacket] * @return uint32 size : size of [WorldPacket]
*/ */
int GetSize(lua_State* L, WorldPacket* packet) int GetSize(Eluna* E, WorldPacket* packet)
{ {
Eluna::Push(L, packet->size()); Eluna::Push(E->L, packet->size());
return 1; return 1;
} }
@@ -36,11 +36,11 @@ namespace LuaPacket
* *
* @param uint32 opcode : the opcode specified to be set for the [WorldPacket] * @param uint32 opcode : the opcode specified to be set for the [WorldPacket]
*/ */
int SetOpcode(lua_State* L, WorldPacket* packet) int SetOpcode(Eluna* E, WorldPacket* packet)
{ {
uint32 opcode = Eluna::CHECKVAL<uint32>(L, 2); uint32 opcode = Eluna::CHECKVAL<uint32>(E->L, 2);
if (opcode >= NUM_MSG_TYPES) if (opcode >= NUM_MSG_TYPES)
return luaL_argerror(L, 2, "valid opcode expected"); return luaL_argerror(E->L, 2, "valid opcode expected");
packet->SetOpcode((OpcodesList)opcode); packet->SetOpcode((OpcodesList)opcode);
return 0; return 0;
} }
@@ -50,11 +50,11 @@ namespace LuaPacket
* *
* @return int8 value * @return int8 value
*/ */
int ReadByte(lua_State* L, WorldPacket* packet) int ReadByte(Eluna* E, WorldPacket* packet)
{ {
int8 _byte; int8 _byte;
(*packet) >> _byte; (*packet) >> _byte;
Eluna::Push(L, _byte); Eluna::Push(E->L, _byte);
return 1; return 1;
} }
@@ -63,11 +63,11 @@ namespace LuaPacket
* *
* @return uint8 value * @return uint8 value
*/ */
int ReadUByte(lua_State* L, WorldPacket* packet) int ReadUByte(Eluna* E, WorldPacket* packet)
{ {
uint8 _ubyte; uint8 _ubyte;
(*packet) >> _ubyte; (*packet) >> _ubyte;
Eluna::Push(L, _ubyte); Eluna::Push(E->L, _ubyte);
return 1; return 1;
} }
@@ -76,11 +76,11 @@ namespace LuaPacket
* *
* @return int16 value * @return int16 value
*/ */
int ReadShort(lua_State* L, WorldPacket* packet) int ReadShort(Eluna* E, WorldPacket* packet)
{ {
int16 _short; int16 _short;
(*packet) >> _short; (*packet) >> _short;
Eluna::Push(L, _short); Eluna::Push(E->L, _short);
return 1; return 1;
} }
@@ -89,11 +89,11 @@ namespace LuaPacket
* *
* @return uint16 value * @return uint16 value
*/ */
int ReadUShort(lua_State* L, WorldPacket* packet) int ReadUShort(Eluna* E, WorldPacket* packet)
{ {
uint16 _ushort; uint16 _ushort;
(*packet) >> _ushort; (*packet) >> _ushort;
Eluna::Push(L, _ushort); Eluna::Push(E->L, _ushort);
return 1; return 1;
} }
@@ -102,11 +102,11 @@ namespace LuaPacket
* *
* @return int32 value * @return int32 value
*/ */
int ReadLong(lua_State* L, WorldPacket* packet) int ReadLong(Eluna* E, WorldPacket* packet)
{ {
int32 _long; int32 _long;
(*packet) >> _long; (*packet) >> _long;
Eluna::Push(L, _long); Eluna::Push(E->L, _long);
return 1; return 1;
} }
@@ -115,11 +115,11 @@ namespace LuaPacket
* *
* @return uint32 value * @return uint32 value
*/ */
int ReadULong(lua_State* L, WorldPacket* packet) int ReadULong(Eluna* E, WorldPacket* packet)
{ {
uint32 _ulong; uint32 _ulong;
(*packet) >> _ulong; (*packet) >> _ulong;
Eluna::Push(L, _ulong); Eluna::Push(E->L, _ulong);
return 1; return 1;
} }
@@ -128,11 +128,11 @@ namespace LuaPacket
* *
* @return float value * @return float value
*/ */
int ReadFloat(lua_State* L, WorldPacket* packet) int ReadFloat(Eluna* E, WorldPacket* packet)
{ {
float _val; float _val;
(*packet) >> _val; (*packet) >> _val;
Eluna::Push(L, _val); Eluna::Push(E->L, _val);
return 1; return 1;
} }
@@ -141,11 +141,11 @@ namespace LuaPacket
* *
* @return double value * @return double value
*/ */
int ReadDouble(lua_State* L, WorldPacket* packet) int ReadDouble(Eluna* E, WorldPacket* packet)
{ {
double _val; double _val;
(*packet) >> _val; (*packet) >> _val;
Eluna::Push(L, _val); Eluna::Push(E->L, _val);
return 1; return 1;
} }
@@ -154,11 +154,11 @@ namespace LuaPacket
* *
* @return uint64 value : value returned as string * @return uint64 value : value returned as string
*/ */
int ReadGUID(lua_State* L, WorldPacket* packet) int ReadGUID(Eluna* E, WorldPacket* packet)
{ {
uint64 guid; uint64 guid;
(*packet) >> guid; (*packet) >> guid;
Eluna::Push(L, guid); Eluna::Push(E->L, guid);
return 1; return 1;
} }
@@ -167,11 +167,11 @@ namespace LuaPacket
* *
* @return string value * @return string value
*/ */
int ReadString(lua_State* L, WorldPacket* packet) int ReadString(Eluna* E, WorldPacket* packet)
{ {
std::string _val; std::string _val;
(*packet) >> _val; (*packet) >> _val;
Eluna::Push(L, _val); Eluna::Push(E->L, _val);
return 1; return 1;
} }
@@ -180,9 +180,9 @@ namespace LuaPacket
* *
* @param uint64 value : the value to be written to the [WorldPacket] * @param uint64 value : the value to be written to the [WorldPacket]
*/ */
int WriteGUID(lua_State* L, WorldPacket* packet) int WriteGUID(Eluna* E, WorldPacket* packet)
{ {
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2); uint64 guid = Eluna::CHECKVAL<uint64>(E->L, 2);
(*packet) << guid; (*packet) << guid;
return 0; return 0;
} }
@@ -192,9 +192,9 @@ namespace LuaPacket
* *
* @param string value : the string to be written to the [WorldPacket] * @param string value : the string to be written to the [WorldPacket]
*/ */
int WriteString(lua_State* L, WorldPacket* packet) int WriteString(Eluna* E, WorldPacket* packet)
{ {
std::string _val = Eluna::CHECKVAL<std::string>(L, 2); std::string _val = Eluna::CHECKVAL<std::string>(E->L, 2);
(*packet) << _val; (*packet) << _val;
return 0; return 0;
} }
@@ -204,9 +204,9 @@ namespace LuaPacket
* *
* @param int8 value : the int8 value to be written to the [WorldPacket] * @param int8 value : the int8 value to be written to the [WorldPacket]
*/ */
int WriteByte(lua_State* L, WorldPacket* packet) int WriteByte(Eluna* E, WorldPacket* packet)
{ {
int8 byte = Eluna::CHECKVAL<int8>(L, 2); int8 byte = Eluna::CHECKVAL<int8>(E->L, 2);
(*packet) << byte; (*packet) << byte;
return 0; return 0;
} }
@@ -216,9 +216,9 @@ namespace LuaPacket
* *
* @param uint8 value : the uint8 value to be written to the [WorldPacket] * @param uint8 value : the uint8 value to be written to the [WorldPacket]
*/ */
int WriteUByte(lua_State* L, WorldPacket* packet) int WriteUByte(Eluna* E, WorldPacket* packet)
{ {
uint8 byte = Eluna::CHECKVAL<uint8>(L, 2); uint8 byte = Eluna::CHECKVAL<uint8>(E->L, 2);
(*packet) << byte; (*packet) << byte;
return 0; return 0;
} }
@@ -228,9 +228,9 @@ namespace LuaPacket
* *
* @param int16 value : the int16 value to be written to the [WorldPacket] * @param int16 value : the int16 value to be written to the [WorldPacket]
*/ */
int WriteShort(lua_State* L, WorldPacket* packet) int WriteShort(Eluna* E, WorldPacket* packet)
{ {
int16 _short = Eluna::CHECKVAL<int16>(L, 2); int16 _short = Eluna::CHECKVAL<int16>(E->L, 2);
(*packet) << _short; (*packet) << _short;
return 0; return 0;
} }
@@ -240,9 +240,9 @@ namespace LuaPacket
* *
* @param uint16 value : the uint16 value to be written to the [WorldPacket] * @param uint16 value : the uint16 value to be written to the [WorldPacket]
*/ */
int WriteUShort(lua_State* L, WorldPacket* packet) int WriteUShort(Eluna* E, WorldPacket* packet)
{ {
uint16 _ushort = Eluna::CHECKVAL<uint16>(L, 2); uint16 _ushort = Eluna::CHECKVAL<uint16>(E->L, 2);
(*packet) << _ushort; (*packet) << _ushort;
return 0; return 0;
} }
@@ -252,9 +252,9 @@ namespace LuaPacket
* *
* @param int32 value : the int32 value to be written to the [WorldPacket] * @param int32 value : the int32 value to be written to the [WorldPacket]
*/ */
int WriteLong(lua_State* L, WorldPacket* packet) int WriteLong(Eluna* E, WorldPacket* packet)
{ {
int32 _long = Eluna::CHECKVAL<int32>(L, 2); int32 _long = Eluna::CHECKVAL<int32>(E->L, 2);
(*packet) << _long; (*packet) << _long;
return 0; return 0;
} }
@@ -264,9 +264,9 @@ namespace LuaPacket
* *
* @param uint32 value : the uint32 value to be written to the [WorldPacket] * @param uint32 value : the uint32 value to be written to the [WorldPacket]
*/ */
int WriteULong(lua_State* L, WorldPacket* packet) int WriteULong(Eluna* E, WorldPacket* packet)
{ {
uint32 _ulong = Eluna::CHECKVAL<uint32>(L, 2); uint32 _ulong = Eluna::CHECKVAL<uint32>(E->L, 2);
(*packet) << _ulong; (*packet) << _ulong;
return 0; return 0;
} }
@@ -276,9 +276,9 @@ namespace LuaPacket
* *
* @param float value : the float value to be written to the [WorldPacket] * @param float value : the float value to be written to the [WorldPacket]
*/ */
int WriteFloat(lua_State* L, WorldPacket* packet) int WriteFloat(Eluna* E, WorldPacket* packet)
{ {
float _val = Eluna::CHECKVAL<float>(L, 2); float _val = Eluna::CHECKVAL<float>(E->L, 2);
(*packet) << _val; (*packet) << _val;
return 0; return 0;
} }
@@ -288,9 +288,9 @@ namespace LuaPacket
* *
* @param double value : the double value to be written to the [WorldPacket] * @param double value : the double value to be written to the [WorldPacket]
*/ */
int WriteDouble(lua_State* L, WorldPacket* packet) int WriteDouble(Eluna* E, WorldPacket* packet)
{ {
double _val = Eluna::CHECKVAL<double>(L, 2); double _val = Eluna::CHECKVAL<double>(E->L, 2);
(*packet) << _val; (*packet) << _val;
return 0; return 0;
} }