mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Eluna Fix static analysis noted warnings and errors
This commit is contained in:
@@ -73,9 +73,10 @@ public:
|
||||
{
|
||||
for (EventToFunctionsMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
|
||||
{
|
||||
for (FunctionRefVector::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
FunctionRefVector& funcrefvec = itr->second;
|
||||
for (FunctionRefVector::iterator it = funcrefvec.begin(); it != funcrefvec.end(); ++it)
|
||||
delete *it;
|
||||
itr->second.clear();
|
||||
funcrefvec.clear();
|
||||
}
|
||||
Bindings.clear();
|
||||
}
|
||||
@@ -145,13 +146,15 @@ public:
|
||||
{
|
||||
for (EntryToEventsMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
|
||||
{
|
||||
for (EventToFunctionsMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
EventToFunctionsMap& funcmap = itr->second;
|
||||
for (EventToFunctionsMap::iterator it = funcmap.begin(); it != funcmap.end(); ++it)
|
||||
{
|
||||
for (FunctionRefVector::iterator i = it->second.begin(); i != it->second.end(); ++i)
|
||||
FunctionRefVector& funcrefvec = it->second;
|
||||
for (FunctionRefVector::iterator i = funcrefvec.begin(); i != funcrefvec.end(); ++i)
|
||||
delete *i;
|
||||
it->second.clear();
|
||||
funcrefvec.clear();
|
||||
}
|
||||
itr->second.clear();
|
||||
funcmap.clear();
|
||||
}
|
||||
Bindings.clear();
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ bool ElunaUtil::ObjectDistanceOrderPred::operator()(WorldObject const* pLeft, Wo
|
||||
}
|
||||
|
||||
ElunaUtil::WorldObjectInRangeCheck::WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
|
||||
uint16 typeMask, uint32 entry, uint32 hostile) : i_nearest(nearest),
|
||||
i_obj(obj), i_range(range), i_typeMask(typeMask), i_entry(entry), i_hostile(hostile)
|
||||
uint16 typeMask, uint32 entry, uint32 hostile) :
|
||||
i_obj(obj), i_hostile(hostile), i_entry(entry), i_range(range), i_typeMask(typeMask), i_nearest(nearest)
|
||||
{
|
||||
}
|
||||
WorldObject const& ElunaUtil::WorldObjectInRangeCheck::GetFocusObject() const
|
||||
|
||||
@@ -108,12 +108,12 @@ namespace ElunaUtil
|
||||
WorldObject const& GetFocusObject() const;
|
||||
bool operator()(WorldObject* u);
|
||||
|
||||
bool i_nearest;
|
||||
WorldObject const* i_obj;
|
||||
uint32 i_hostile;
|
||||
uint32 i_entry;
|
||||
float i_range;
|
||||
uint16 i_typeMask;
|
||||
uint32 i_entry;
|
||||
uint32 i_hostile;
|
||||
bool i_nearest;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -1532,7 +1532,7 @@ namespace LuaGlobalFunctions
|
||||
int CreatePacket(Eluna* /*E*/, lua_State* L)
|
||||
{
|
||||
uint32 opcode = Eluna::CHECKVAL<uint32>(L, 1);
|
||||
uint32 size = Eluna::CHECKVAL<uint32>(L, 2);
|
||||
size_t size = Eluna::CHECKVAL<size_t>(L, 2);
|
||||
if (opcode >= NUM_MSG_TYPES)
|
||||
return luaL_argerror(L, 1, "valid opcode expected");
|
||||
|
||||
|
||||
27
HookMgr.cpp
27
HookMgr.cpp
@@ -46,7 +46,6 @@ using namespace HookMgr;
|
||||
#define EVENT_BEGIN(BINDMAP, EVENT, RET) \
|
||||
if (!BINDMAP->HasEvents(EVENT)) \
|
||||
RET; \
|
||||
lua_State* L = this->L; \
|
||||
const char* _LuaBindType = this->BINDMAP->groupName; \
|
||||
uint32 _LuaEvent = EVENT; \
|
||||
int _LuaStackTop = lua_gettop(L); \
|
||||
@@ -79,7 +78,6 @@ using namespace HookMgr;
|
||||
#define ENTRY_BEGIN(BINDMAP, ENTRY, EVENT, RET) \
|
||||
if (!BINDMAP->HasEvents(ENTRY, EVENT)) \
|
||||
RET; \
|
||||
lua_State* L = this->L; \
|
||||
const char* _LuaBindType = this->BINDMAP->groupName; \
|
||||
uint32 _LuaEvent = EVENT; \
|
||||
int _LuaStackTop = lua_gettop(L); \
|
||||
@@ -382,7 +380,7 @@ void Eluna::OnShutdown()
|
||||
ENDCALL();
|
||||
}
|
||||
|
||||
void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code)
|
||||
void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, const std::string& code)
|
||||
{
|
||||
ENTRY_BEGIN(ItemGossipBindings, item->GetEntry(), GOSSIP_EVENT_ON_SELECT, return);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
@@ -398,7 +396,7 @@ void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender,
|
||||
ENDCALL();
|
||||
}
|
||||
|
||||
void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code)
|
||||
void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code)
|
||||
{
|
||||
ENTRY_BEGIN(playerGossipBindings, menuId, GOSSIP_EVENT_ON_SELECT, return);
|
||||
pPlayer->PlayerTalkClass->ClearMenus();
|
||||
@@ -744,7 +742,12 @@ void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount)
|
||||
EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_MONEY_CHANGE, return);
|
||||
Push(L, pPlayer);
|
||||
Push(L, amount);
|
||||
EVENT_EXECUTE(0);
|
||||
EVENT_EXECUTE(1);
|
||||
FOR_RETS(i)
|
||||
{
|
||||
if (lua_isnumber(L, i))
|
||||
amount = CHECKVAL<int32>(L, i, amount);
|
||||
}
|
||||
ENDCALL();
|
||||
}
|
||||
|
||||
@@ -1187,7 +1190,12 @@ void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, b
|
||||
Push(L, player);
|
||||
Push(L, amount);
|
||||
Push(L, isRepair); // isRepair not a part of Mangos, implement?
|
||||
EVENT_EXECUTE(0);
|
||||
EVENT_EXECUTE(1);
|
||||
FOR_RETS(i)
|
||||
{
|
||||
if (lua_isnumber(L, i))
|
||||
amount = CHECKVAL<uint32>(L, i, amount);
|
||||
}
|
||||
ENDCALL();
|
||||
}
|
||||
|
||||
@@ -1197,7 +1205,12 @@ void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount)
|
||||
Push(L, guild);
|
||||
Push(L, player);
|
||||
Push(L, amount);
|
||||
EVENT_EXECUTE(0);
|
||||
EVENT_EXECUTE(1);
|
||||
FOR_RETS(i)
|
||||
{
|
||||
if (lua_isnumber(L, i))
|
||||
amount = CHECKVAL<uint32>(L, i, amount);
|
||||
}
|
||||
ENDCALL();
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace HookMgr
|
||||
PLAYER_EVENT_ON_DUEL_END = 11, // (event, winner, loser, type)
|
||||
PLAYER_EVENT_ON_GIVE_XP = 12, // (event, player, amount, victim) - Can return new XP amount
|
||||
PLAYER_EVENT_ON_LEVEL_CHANGE = 13, // (event, player, oldLevel)
|
||||
PLAYER_EVENT_ON_MONEY_CHANGE = 14, // (event, player, amount)
|
||||
PLAYER_EVENT_ON_MONEY_CHANGE = 14, // (event, player, amount) - Can return new money amount
|
||||
PLAYER_EVENT_ON_REPUTATION_CHANGE = 15, // (event, player, factionId, standing, incremental) - Can return new standing
|
||||
PLAYER_EVENT_ON_TALENTS_CHANGE = 16, // (event, player, points)
|
||||
PLAYER_EVENT_ON_TALENTS_RESET = 17, // (event, player, noCost)
|
||||
@@ -155,8 +155,8 @@ namespace HookMgr
|
||||
GUILD_EVENT_ON_INFO_CHANGE = 4, // (event, guild, newInfo)
|
||||
GUILD_EVENT_ON_CREATE = 5, // (event, guild, leader, name) // Not on TC
|
||||
GUILD_EVENT_ON_DISBAND = 6, // (event, guild)
|
||||
GUILD_EVENT_ON_MONEY_WITHDRAW = 7, // (event, guild, player, amount, isRepair)
|
||||
GUILD_EVENT_ON_MONEY_DEPOSIT = 8, // (event, guild, player, amount)
|
||||
GUILD_EVENT_ON_MONEY_WITHDRAW = 7, // (event, guild, player, amount, isRepair) - Can return new money amount
|
||||
GUILD_EVENT_ON_MONEY_DEPOSIT = 8, // (event, guild, player, amount) - Can return new money amount
|
||||
GUILD_EVENT_ON_ITEM_MOVE = 9, // (event, guild, player, item, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId) // TODO
|
||||
GUILD_EVENT_ON_EVENT = 10, // (event, guild, eventType, plrGUIDLow1, plrGUIDLow2, newRank) // TODO
|
||||
GUILD_EVENT_ON_BANK_EVENT = 11, // (event, guild, eventType, tabId, playerGUIDLow, itemOrMoney, itemStackCount, destTabId)
|
||||
|
||||
236
LuaEngine.cpp
236
LuaEngine.cpp
@@ -55,7 +55,7 @@ void Eluna::Initialize()
|
||||
lua_folderpath.replace(0, 1, home);
|
||||
#endif
|
||||
ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", lua_folderpath.c_str());
|
||||
lua_requirepath = "";
|
||||
lua_requirepath.clear();
|
||||
GetScripts(lua_folderpath);
|
||||
// Erase last ;
|
||||
if (!lua_requirepath.empty())
|
||||
@@ -215,7 +215,7 @@ Eluna::~Eluna()
|
||||
lua_close(L);
|
||||
}
|
||||
|
||||
void Eluna::AddScriptPath(std::string filename, std::string fullpath)
|
||||
void Eluna::AddScriptPath(std::string filename, const std::string& fullpath)
|
||||
{
|
||||
ELUNA_LOG_DEBUG("[Eluna]: AddScriptPath Checking file `%s`", fullpath.c_str());
|
||||
|
||||
@@ -421,11 +421,11 @@ void Eluna::InvalidateObjects()
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
void Eluna::report(lua_State* L)
|
||||
void Eluna::report(lua_State* luastate)
|
||||
{
|
||||
const char* msg = lua_tostring(L, -1);
|
||||
const char* msg = lua_tostring(luastate, -1);
|
||||
ELUNA_LOG_ERROR("%s", msg);
|
||||
lua_pop(L, 1);
|
||||
lua_pop(luastate, 1);
|
||||
}
|
||||
|
||||
void Eluna::ExecuteCall(int params, int res)
|
||||
@@ -446,270 +446,270 @@ void Eluna::ExecuteCall(int params, int res)
|
||||
--event_level;
|
||||
}
|
||||
|
||||
void Eluna::Push(lua_State* L)
|
||||
void Eluna::Push(lua_State* luastate)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
lua_pushnil(luastate);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const long long l)
|
||||
void Eluna::Push(lua_State* luastate, const long long l)
|
||||
{
|
||||
ElunaTemplate<long long>::Push(L, new long long(l));
|
||||
ElunaTemplate<long long>::Push(luastate, new long long(l));
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const unsigned long long l)
|
||||
void Eluna::Push(lua_State* luastate, const unsigned long long l)
|
||||
{
|
||||
ElunaTemplate<unsigned long long>::Push(L, new unsigned long long(l));
|
||||
ElunaTemplate<unsigned long long>::Push(luastate, new unsigned long long(l));
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const long l)
|
||||
void Eluna::Push(lua_State* luastate, const long l)
|
||||
{
|
||||
Push(L, static_cast<long long>(l));
|
||||
Push(luastate, static_cast<long long>(l));
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const unsigned long l)
|
||||
void Eluna::Push(lua_State* luastate, const unsigned long l)
|
||||
{
|
||||
Push(L, static_cast<unsigned long long>(l));
|
||||
Push(luastate, static_cast<unsigned long long>(l));
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const int i)
|
||||
void Eluna::Push(lua_State* luastate, const int i)
|
||||
{
|
||||
lua_pushinteger(L, i);
|
||||
lua_pushinteger(luastate, i);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const unsigned int u)
|
||||
void Eluna::Push(lua_State* luastate, const unsigned int u)
|
||||
{
|
||||
lua_pushunsigned(L, u);
|
||||
lua_pushunsigned(luastate, u);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const double d)
|
||||
void Eluna::Push(lua_State* luastate, const double d)
|
||||
{
|
||||
lua_pushnumber(L, d);
|
||||
lua_pushnumber(luastate, d);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const float f)
|
||||
void Eluna::Push(lua_State* luastate, const float f)
|
||||
{
|
||||
lua_pushnumber(L, f);
|
||||
lua_pushnumber(luastate, f);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const bool b)
|
||||
void Eluna::Push(lua_State* luastate, const bool b)
|
||||
{
|
||||
lua_pushboolean(L, b);
|
||||
lua_pushboolean(luastate, b);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const std::string& str)
|
||||
void Eluna::Push(lua_State* luastate, const std::string& str)
|
||||
{
|
||||
lua_pushstring(L, str.c_str());
|
||||
lua_pushstring(luastate, str.c_str());
|
||||
}
|
||||
void Eluna::Push(lua_State* L, const char* str)
|
||||
void Eluna::Push(lua_State* luastate, const char* str)
|
||||
{
|
||||
lua_pushstring(L, str);
|
||||
lua_pushstring(luastate, str);
|
||||
}
|
||||
void Eluna::Push(lua_State* L, Pet const* pet)
|
||||
void Eluna::Push(lua_State* luastate, Pet const* pet)
|
||||
{
|
||||
Push(L, pet->ToCreature());
|
||||
Push(luastate, pet->ToCreature());
|
||||
}
|
||||
void Eluna::Push(lua_State* L, TempSummon const* summon)
|
||||
void Eluna::Push(lua_State* luastate, TempSummon const* summon)
|
||||
{
|
||||
Push(L, summon->ToCreature());
|
||||
Push(luastate, summon->ToCreature());
|
||||
}
|
||||
void Eluna::Push(lua_State* L, Unit const* unit)
|
||||
void Eluna::Push(lua_State* luastate, Unit const* unit)
|
||||
{
|
||||
if (!unit)
|
||||
{
|
||||
Push(L);
|
||||
Push(luastate);
|
||||
return;
|
||||
}
|
||||
switch (unit->GetTypeId())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
Push(L, unit->ToCreature());
|
||||
Push(luastate, unit->ToCreature());
|
||||
break;
|
||||
case TYPEID_PLAYER:
|
||||
Push(L, unit->ToPlayer());
|
||||
Push(luastate, unit->ToPlayer());
|
||||
break;
|
||||
default:
|
||||
ElunaTemplate<Unit>::Push(L, unit);
|
||||
ElunaTemplate<Unit>::Push(luastate, unit);
|
||||
}
|
||||
}
|
||||
void Eluna::Push(lua_State* L, WorldObject const* obj)
|
||||
void Eluna::Push(lua_State* luastate, WorldObject const* obj)
|
||||
{
|
||||
if (!obj)
|
||||
{
|
||||
Push(L);
|
||||
Push(luastate);
|
||||
return;
|
||||
}
|
||||
switch (obj->GetTypeId())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
Push(L, obj->ToCreature());
|
||||
Push(luastate, obj->ToCreature());
|
||||
break;
|
||||
case TYPEID_PLAYER:
|
||||
Push(L, obj->ToPlayer());
|
||||
Push(luastate, obj->ToPlayer());
|
||||
break;
|
||||
case TYPEID_GAMEOBJECT:
|
||||
Push(L, obj->ToGameObject());
|
||||
Push(luastate, obj->ToGameObject());
|
||||
break;
|
||||
case TYPEID_CORPSE:
|
||||
Push(L, obj->ToCorpse());
|
||||
Push(luastate, obj->ToCorpse());
|
||||
break;
|
||||
default:
|
||||
ElunaTemplate<WorldObject>::Push(L, obj);
|
||||
ElunaTemplate<WorldObject>::Push(luastate, obj);
|
||||
}
|
||||
}
|
||||
void Eluna::Push(lua_State* L, Object const* obj)
|
||||
void Eluna::Push(lua_State* luastate, Object const* obj)
|
||||
{
|
||||
if (!obj)
|
||||
{
|
||||
Push(L);
|
||||
Push(luastate);
|
||||
return;
|
||||
}
|
||||
switch (obj->GetTypeId())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
Push(L, obj->ToCreature());
|
||||
Push(luastate, obj->ToCreature());
|
||||
break;
|
||||
case TYPEID_PLAYER:
|
||||
Push(L, obj->ToPlayer());
|
||||
Push(luastate, obj->ToPlayer());
|
||||
break;
|
||||
case TYPEID_GAMEOBJECT:
|
||||
Push(L, obj->ToGameObject());
|
||||
Push(luastate, obj->ToGameObject());
|
||||
break;
|
||||
case TYPEID_CORPSE:
|
||||
Push(L, obj->ToCorpse());
|
||||
Push(luastate, obj->ToCorpse());
|
||||
break;
|
||||
default:
|
||||
ElunaTemplate<Object>::Push(L, obj);
|
||||
ElunaTemplate<Object>::Push(luastate, obj);
|
||||
}
|
||||
}
|
||||
|
||||
static int CheckIntegerRange(lua_State* L, int narg, int min, int max)
|
||||
static int CheckIntegerRange(lua_State* luastate, int narg, int min, int max)
|
||||
{
|
||||
double value = luaL_checknumber(L, narg);
|
||||
double value = luaL_checknumber(luastate, narg);
|
||||
char error_buffer[64];
|
||||
|
||||
if (value > max)
|
||||
{
|
||||
snprintf(error_buffer, 64, "value must be less than or equal to %i", max);
|
||||
return luaL_argerror(L, narg, error_buffer);
|
||||
return luaL_argerror(luastate, narg, error_buffer);
|
||||
}
|
||||
|
||||
if (value < min)
|
||||
{
|
||||
snprintf(error_buffer, 64, "value must be greater than or equal to %i", min);
|
||||
return luaL_argerror(L, narg, error_buffer);
|
||||
return luaL_argerror(luastate, narg, error_buffer);
|
||||
}
|
||||
|
||||
return static_cast<int>(value);
|
||||
}
|
||||
|
||||
static unsigned int CheckUnsignedRange(lua_State* L, int narg, unsigned int max)
|
||||
static unsigned int CheckUnsignedRange(lua_State* luastate, int narg, unsigned int max)
|
||||
{
|
||||
double value = luaL_checknumber(L, narg);
|
||||
double value = luaL_checknumber(luastate, narg);
|
||||
char error_buffer[64];
|
||||
|
||||
if (value < 0)
|
||||
return luaL_argerror(L, narg, "value must be greater than or equal to 0");
|
||||
return luaL_argerror(luastate, narg, "value must be greater than or equal to 0");
|
||||
|
||||
if (value > max)
|
||||
{
|
||||
snprintf(error_buffer, 64, "value must be less than or equal to %u", max);
|
||||
return luaL_argerror(L, narg, error_buffer);
|
||||
return luaL_argerror(luastate, narg, error_buffer);
|
||||
}
|
||||
|
||||
return static_cast<unsigned int>(value);
|
||||
}
|
||||
|
||||
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg)
|
||||
template<> bool Eluna::CHECKVAL<bool>(lua_State* luastate, int narg)
|
||||
{
|
||||
return lua_toboolean(L, narg) != 0;
|
||||
return lua_toboolean(luastate, narg) != 0;
|
||||
}
|
||||
template<> float Eluna::CHECKVAL<float>(lua_State* L, int narg)
|
||||
template<> float Eluna::CHECKVAL<float>(lua_State* luastate, int narg)
|
||||
{
|
||||
return luaL_checknumber(L, narg);
|
||||
return luaL_checknumber(luastate, narg);
|
||||
}
|
||||
template<> double Eluna::CHECKVAL<double>(lua_State* L, int narg)
|
||||
template<> double Eluna::CHECKVAL<double>(lua_State* luastate, int narg)
|
||||
{
|
||||
return luaL_checknumber(L, narg);
|
||||
return luaL_checknumber(luastate, narg);
|
||||
}
|
||||
template<> signed char Eluna::CHECKVAL<signed char>(lua_State* L, int narg)
|
||||
template<> signed char Eluna::CHECKVAL<signed char>(lua_State* luastate, int narg)
|
||||
{
|
||||
return CheckIntegerRange(L, narg, SCHAR_MIN, SCHAR_MAX);
|
||||
return CheckIntegerRange(luastate, narg, SCHAR_MIN, SCHAR_MAX);
|
||||
}
|
||||
template<> unsigned char Eluna::CHECKVAL<unsigned char>(lua_State* L, int narg)
|
||||
template<> unsigned char Eluna::CHECKVAL<unsigned char>(lua_State* luastate, int narg)
|
||||
{
|
||||
return CheckUnsignedRange(L, narg, UCHAR_MAX);
|
||||
return CheckUnsignedRange(luastate, narg, UCHAR_MAX);
|
||||
}
|
||||
template<> short Eluna::CHECKVAL<short>(lua_State* L, int narg)
|
||||
template<> short Eluna::CHECKVAL<short>(lua_State* luastate, int narg)
|
||||
{
|
||||
return CheckIntegerRange(L, narg, SHRT_MIN, SHRT_MAX);
|
||||
return CheckIntegerRange(luastate, narg, SHRT_MIN, SHRT_MAX);
|
||||
}
|
||||
template<> unsigned short Eluna::CHECKVAL<unsigned short>(lua_State* L, int narg)
|
||||
template<> unsigned short Eluna::CHECKVAL<unsigned short>(lua_State* luastate, int narg)
|
||||
{
|
||||
return CheckUnsignedRange(L, narg, USHRT_MAX);
|
||||
return CheckUnsignedRange(luastate, narg, USHRT_MAX);
|
||||
}
|
||||
template<> int Eluna::CHECKVAL<int>(lua_State* L, int narg)
|
||||
template<> int Eluna::CHECKVAL<int>(lua_State* luastate, int narg)
|
||||
{
|
||||
return CheckIntegerRange(L, narg, INT_MIN, INT_MAX);
|
||||
return CheckIntegerRange(luastate, narg, INT_MIN, INT_MAX);
|
||||
}
|
||||
template<> unsigned int Eluna::CHECKVAL<unsigned int>(lua_State* L, int narg)
|
||||
template<> unsigned int Eluna::CHECKVAL<unsigned int>(lua_State* luastate, int narg)
|
||||
{
|
||||
return CheckUnsignedRange(L, narg, UINT_MAX);
|
||||
return CheckUnsignedRange(luastate, narg, UINT_MAX);
|
||||
}
|
||||
template<> const char* Eluna::CHECKVAL<const char*>(lua_State* L, int narg)
|
||||
template<> const char* Eluna::CHECKVAL<const char*>(lua_State* luastate, int narg)
|
||||
{
|
||||
return luaL_checkstring(L, narg);
|
||||
return luaL_checkstring(luastate, narg);
|
||||
}
|
||||
template<> std::string Eluna::CHECKVAL<std::string>(lua_State* L, int narg)
|
||||
template<> std::string Eluna::CHECKVAL<std::string>(lua_State* luastate, int narg)
|
||||
{
|
||||
return luaL_checkstring(L, narg);
|
||||
return luaL_checkstring(luastate, narg);
|
||||
}
|
||||
template<> long long Eluna::CHECKVAL<long long>(lua_State* L, int narg)
|
||||
template<> long long Eluna::CHECKVAL<long long>(lua_State* luastate, int narg)
|
||||
{
|
||||
if (lua_isnumber(L, narg))
|
||||
return static_cast<long long>(CHECKVAL<double>(L, narg));
|
||||
return *(Eluna::CHECKOBJ<long long>(L, narg, true));
|
||||
if (lua_isnumber(luastate, narg))
|
||||
return static_cast<long long>(CHECKVAL<double>(luastate, narg));
|
||||
return *(Eluna::CHECKOBJ<long long>(luastate, narg, true));
|
||||
}
|
||||
template<> unsigned long long Eluna::CHECKVAL<unsigned long long>(lua_State* L, int narg)
|
||||
template<> unsigned long long Eluna::CHECKVAL<unsigned long long>(lua_State* luastate, int narg)
|
||||
{
|
||||
if (lua_isnumber(L, narg))
|
||||
return static_cast<unsigned long long>(CHECKVAL<uint32>(L, narg));
|
||||
return *(Eluna::CHECKOBJ<unsigned long long>(L, narg, true));
|
||||
if (lua_isnumber(luastate, narg))
|
||||
return static_cast<unsigned long long>(CHECKVAL<uint32>(luastate, narg));
|
||||
return *(Eluna::CHECKOBJ<unsigned long long>(luastate, narg, true));
|
||||
}
|
||||
template<> long Eluna::CHECKVAL<long>(lua_State* L, int narg)
|
||||
template<> long Eluna::CHECKVAL<long>(lua_State* luastate, int narg)
|
||||
{
|
||||
return static_cast<long>(CHECKVAL<long long>(L, narg));
|
||||
return static_cast<long>(CHECKVAL<long long>(luastate, narg));
|
||||
}
|
||||
template<> unsigned long Eluna::CHECKVAL<unsigned long>(lua_State* L, int narg)
|
||||
template<> unsigned long Eluna::CHECKVAL<unsigned long>(lua_State* luastate, int narg)
|
||||
{
|
||||
return static_cast<unsigned long>(CHECKVAL<unsigned long long>(L, narg));
|
||||
return static_cast<unsigned long>(CHECKVAL<unsigned long long>(luastate, narg));
|
||||
}
|
||||
|
||||
template<> Object* Eluna::CHECKOBJ<Object>(lua_State* L, int narg, bool error)
|
||||
template<> Object* Eluna::CHECKOBJ<Object>(lua_State* luastate, int narg, bool error)
|
||||
{
|
||||
Object* obj = CHECKOBJ<WorldObject>(L, narg, false);
|
||||
Object* obj = CHECKOBJ<WorldObject>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = CHECKOBJ<Item>(L, narg, false);
|
||||
obj = CHECKOBJ<Item>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = ElunaTemplate<Object>::Check(L, narg, error);
|
||||
obj = ElunaTemplate<Object>::Check(luastate, narg, error);
|
||||
return obj;
|
||||
}
|
||||
template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* L, int narg, bool error)
|
||||
template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* luastate, int narg, bool error)
|
||||
{
|
||||
WorldObject* obj = CHECKOBJ<Unit>(L, narg, false);
|
||||
WorldObject* obj = CHECKOBJ<Unit>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = CHECKOBJ<GameObject>(L, narg, false);
|
||||
obj = CHECKOBJ<GameObject>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = CHECKOBJ<Corpse>(L, narg, false);
|
||||
obj = CHECKOBJ<Corpse>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = ElunaTemplate<WorldObject>::Check(L, narg, error);
|
||||
obj = ElunaTemplate<WorldObject>::Check(luastate, narg, error);
|
||||
return obj;
|
||||
}
|
||||
template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* L, int narg, bool error)
|
||||
template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* luastate, int narg, bool error)
|
||||
{
|
||||
Unit* obj = CHECKOBJ<Player>(L, narg, false);
|
||||
Unit* obj = CHECKOBJ<Player>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = CHECKOBJ<Creature>(L, narg, false);
|
||||
obj = CHECKOBJ<Creature>(luastate, narg, false);
|
||||
if (!obj)
|
||||
obj = ElunaTemplate<Unit>::Check(L, narg, error);
|
||||
obj = ElunaTemplate<Unit>::Check(luastate, narg, error);
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* L, int narg, bool error)
|
||||
template<> ElunaObject* Eluna::CHECKOBJ<ElunaObject>(lua_State* luastate, int narg, bool error)
|
||||
{
|
||||
return CHECKTYPE(L, narg, NULL, error);
|
||||
return CHECKTYPE(luastate, narg, NULL, error);
|
||||
}
|
||||
|
||||
ElunaObject* Eluna::CHECKTYPE(lua_State* L, int narg, const char* tname, bool error)
|
||||
ElunaObject* Eluna::CHECKTYPE(lua_State* luastate, int narg, const char* tname, bool error)
|
||||
{
|
||||
bool valid = false;
|
||||
ElunaObject** ptrHold = NULL;
|
||||
@@ -717,19 +717,19 @@ ElunaObject* Eluna::CHECKTYPE(lua_State* L, int narg, const char* tname, bool er
|
||||
if (!tname)
|
||||
{
|
||||
valid = true;
|
||||
ptrHold = static_cast<ElunaObject**>(lua_touserdata(L, narg));
|
||||
ptrHold = static_cast<ElunaObject**>(lua_touserdata(luastate, narg));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lua_getmetatable(L, narg))
|
||||
if (lua_getmetatable(luastate, narg))
|
||||
{
|
||||
luaL_getmetatable(L, tname);
|
||||
if (lua_rawequal(L, -1, -2) == 1)
|
||||
luaL_getmetatable(luastate, tname);
|
||||
if (lua_rawequal(luastate, -1, -2) == 1)
|
||||
{
|
||||
valid = true;
|
||||
ptrHold = static_cast<ElunaObject**>(lua_touserdata(L, narg));
|
||||
ptrHold = static_cast<ElunaObject**>(lua_touserdata(luastate, narg));
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
lua_pop(luastate, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,8 +738,8 @@ ElunaObject* Eluna::CHECKTYPE(lua_State* L, int narg, const char* tname, bool er
|
||||
if (error)
|
||||
{
|
||||
char buff[256];
|
||||
snprintf(buff, 256, "bad argument : %s expected, got %s", tname ? tname : "userdata", luaL_typename(L, narg));
|
||||
luaL_argerror(L, narg, buff);
|
||||
snprintf(buff, 256, "bad argument : %s expected, got %s", tname ? tname : "userdata", luaL_typename(luastate, narg));
|
||||
luaL_argerror(luastate, narg, buff);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
58
LuaEngine.h
58
LuaEngine.h
@@ -150,48 +150,48 @@ public:
|
||||
// This will be called on next update
|
||||
static void ReloadEluna();
|
||||
static void GetScripts(std::string path);
|
||||
static void AddScriptPath(std::string filename, std::string fullpath);
|
||||
static void AddScriptPath(std::string filename, const std::string& fullpath);
|
||||
|
||||
static void report(lua_State*);
|
||||
static void report(lua_State* luastate);
|
||||
void ExecuteCall(int params, int res);
|
||||
void Register(uint8 reg, uint32 id, uint32 evt, int func, uint32 shots);
|
||||
void RunScripts();
|
||||
void InvalidateObjects();
|
||||
|
||||
// Pushes
|
||||
static void Push(lua_State* L); // nil
|
||||
static void Push(lua_State* L, const long long);
|
||||
static void Push(lua_State* L, const unsigned long long);
|
||||
static void Push(lua_State* L, const long);
|
||||
static void Push(lua_State* L, const unsigned long);
|
||||
static void Push(lua_State* L, const int);
|
||||
static void Push(lua_State* L, const unsigned int);
|
||||
static void Push(lua_State* L, const bool);
|
||||
static void Push(lua_State* L, const float);
|
||||
static void Push(lua_State* L, const double);
|
||||
static void Push(lua_State* L, const std::string&);
|
||||
static void Push(lua_State* L, const char*);
|
||||
template<typename T> static void Push(lua_State* L, T const* ptr)
|
||||
static void Push(lua_State* luastate); // nil
|
||||
static void Push(lua_State* luastate, const long long);
|
||||
static void Push(lua_State* luastate, const unsigned long long);
|
||||
static void Push(lua_State* luastate, const long);
|
||||
static void Push(lua_State* luastate, const unsigned long);
|
||||
static void Push(lua_State* luastate, const int);
|
||||
static void Push(lua_State* luastate, const unsigned int);
|
||||
static void Push(lua_State* luastate, const bool);
|
||||
static void Push(lua_State* luastate, const float);
|
||||
static void Push(lua_State* luastate, const double);
|
||||
static void Push(lua_State* luastate, const std::string&);
|
||||
static void Push(lua_State* luastate, const char*);
|
||||
template<typename T> static void Push(lua_State* luastate, T const* ptr)
|
||||
{
|
||||
ElunaTemplate<T>::Push(L, ptr);
|
||||
ElunaTemplate<T>::Push(luastate, ptr);
|
||||
}
|
||||
static void Push(lua_State* L, Object const* obj);
|
||||
static void Push(lua_State* L, WorldObject const* obj);
|
||||
static void Push(lua_State* L, Unit const* unit);
|
||||
static void Push(lua_State* L, Pet const* pet);
|
||||
static void Push(lua_State* L, TempSummon const* summon);
|
||||
static void Push(lua_State* luastate, Object const* obj);
|
||||
static void Push(lua_State* luastate, WorldObject const* obj);
|
||||
static void Push(lua_State* luastate, Unit const* unit);
|
||||
static void Push(lua_State* luastate, Pet const* pet);
|
||||
static void Push(lua_State* luastate, TempSummon const* summon);
|
||||
|
||||
// Checks
|
||||
template<typename T> static T CHECKVAL(lua_State* L, int narg);
|
||||
template<typename T> static T CHECKVAL(lua_State* L, int narg, T def)
|
||||
template<typename T> static T CHECKVAL(lua_State* luastate, int narg);
|
||||
template<typename T> static T CHECKVAL(lua_State* luastate, int narg, T def)
|
||||
{
|
||||
return lua_isnoneornil(L, narg) ? def : CHECKVAL<T>(L, narg);
|
||||
return lua_isnoneornil(luastate, narg) ? def : CHECKVAL<T>(luastate, narg);
|
||||
}
|
||||
template<typename T> static T* CHECKOBJ(lua_State* L, int narg, bool error = true)
|
||||
template<typename T> static T* CHECKOBJ(lua_State* luastate, int narg, bool error = true)
|
||||
{
|
||||
return ElunaTemplate<T>::Check(L, narg, error);
|
||||
return ElunaTemplate<T>::Check(luastate, narg, error);
|
||||
}
|
||||
static ElunaObject* CHECKTYPE(lua_State* L, int narg, const char *tname, bool error = true);
|
||||
static ElunaObject* CHECKTYPE(lua_State* luastate, int narg, const char *tname, bool error = true);
|
||||
|
||||
CreatureAI* GetAI(Creature* creature);
|
||||
|
||||
@@ -218,7 +218,7 @@ public:
|
||||
bool OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& targets);
|
||||
bool OnExpire(Player* pPlayer, ItemTemplate const* pProto);
|
||||
bool OnRemove(Player* pPlayer, Item* item);
|
||||
void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code);
|
||||
void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, const std::string& code);
|
||||
|
||||
/* Creature */
|
||||
bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget);
|
||||
@@ -311,7 +311,7 @@ public:
|
||||
void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent);
|
||||
void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea);
|
||||
void OnMapChanged(Player* pPlayer);
|
||||
void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code);
|
||||
void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code);
|
||||
|
||||
#ifndef CLASSIC
|
||||
#ifndef TBC
|
||||
|
||||
@@ -260,7 +260,7 @@ ElunaRegister<Unit> UnitMethods[] =
|
||||
{ "GetUnfriendlyUnitsInRange", &LuaUnit::GetUnfriendlyUnitsInRange }, // :GetUnfriendlyUnitsInRange([range]) - Returns a list of unfriendly units in range, can return nil
|
||||
{ "GetOwnerGUID", &LuaUnit::GetOwnerGUID }, // :GetOwnerGUID() - Returns the UNIT_FIELD_SUMMONEDBY owner
|
||||
{ "GetCreatorGUID", &LuaUnit::GetCreatorGUID }, // :GetCreatorGUID() - Returns the UNIT_FIELD_CREATEDBY creator
|
||||
{ "GetMinionGUID", &LuaUnit::GetMinionGUID }, // :GetMinionGUID() - Returns the UNIT_FIELD_SUMMON unit's minion GUID
|
||||
{ "GetMinionGUID", &LuaUnit::GetPetGUID }, // :GetMinionGUID() - Decapreted. GetMinionGUID is same as GetPetGUID
|
||||
{ "GetCharmerGUID", &LuaUnit::GetCharmerGUID }, // :GetCharmerGUID() - Returns the UNIT_FIELD_CHARMEDBY charmer
|
||||
{ "GetCharmGUID", &LuaUnit::GetCharmGUID }, // :GetCharmGUID() - Returns the unit's UNIT_FIELD_CHARM guid
|
||||
{ "GetPetGUID", &LuaUnit::GetPetGUID }, // :GetPetGUID() - Returns the unit's pet GUID
|
||||
@@ -313,7 +313,7 @@ ElunaRegister<Unit> UnitMethods[] =
|
||||
{ "SetName", &LuaUnit::SetName }, // :SetName(name) - Sets the unit's name
|
||||
{ "SetSheath", &LuaUnit::SetSheath }, // :SetSheath(SheathState) - Sets unit's sheathstate
|
||||
{ "SetCreatorGUID", &LuaUnit::SetCreatorGUID }, // :SetOwnerGUID(uint64 ownerGUID) - Sets the owner's guid of a summoned creature, etc
|
||||
{ "SetMinionGUID", &LuaUnit::SetMinionGUID }, // :SetCreatorGUID(uint64 creatorGUID) - Sets the UNIT_FIELD_CREATEDBY creator's guid
|
||||
{ "SetMinionGUID", &LuaUnit::SetPetGUID }, // Decapreted. Same as SetPetGUID
|
||||
{ "SetCharmerGUID", &LuaUnit::SetCharmerGUID }, // :SetCharmerGUID(uint64 ownerGUID) - Sets the UNIT_FIELD_CHARMEDBY charmer GUID
|
||||
{ "SetPetGUID", &LuaUnit::SetPetGUID }, // :SetPetGUID(uint64 guid) - Sets the pet's guid
|
||||
#if (!defined(TBC) && !defined(CLASSIC))
|
||||
|
||||
@@ -1994,9 +1994,11 @@ namespace LuaPlayer
|
||||
uint32 muteseconds = Eluna::CHECKVAL<uint32>(L, 2);
|
||||
/*const char* reason = luaL_checkstring(E, 2);*/ // Mangos does not have a reason field in database.
|
||||
|
||||
uint64 muteTime = time(NULL) + muteseconds;
|
||||
time_t muteTime = time(NULL) + muteseconds;
|
||||
player->GetSession()->m_muteTime = muteTime;
|
||||
LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'", muteTime, player->GetSession()->GetAccountId());
|
||||
std::ostringstream oss;
|
||||
oss << "UPDATE account SET mutetime = " << muteTime << " WHERE id = " << player->GetSession()->GetAccountId();
|
||||
LoginDatabase.PExecute("%s", oss.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -412,16 +412,6 @@ namespace LuaUnit
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GetMinionGUID(Eluna* /*E*/, lua_State* L, Unit* unit)
|
||||
{
|
||||
#ifndef TRINITY
|
||||
Eluna::Push(L, unit->GetPetGuid());
|
||||
#else
|
||||
Eluna::Push(L, unit->GetPetGUID());
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int GetCharmerGUID(Eluna* /*E*/, lua_State* L, Unit* unit)
|
||||
{
|
||||
#ifndef TRINITY
|
||||
@@ -1087,20 +1077,9 @@ namespace LuaUnit
|
||||
{
|
||||
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2);
|
||||
#ifndef TRINITY
|
||||
unit->SetOwnerGuid(ObjectGuid(guid));
|
||||
unit->SetCreatorGuid(ObjectGuid(guid));
|
||||
#else
|
||||
unit->SetOwnerGUID(ObjectGuid(guid));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SetMinionGUID(Eluna* /*E*/, lua_State* L, Unit* unit)
|
||||
{
|
||||
uint64 guid = Eluna::CHECKVAL<uint64>(L, 2);
|
||||
#ifndef TRINITY
|
||||
unit->SetPetGuid(ObjectGuid(guid));
|
||||
#else
|
||||
unit->SetMinionGUID(ObjectGuid(guid));
|
||||
unit->SetCreatorGUID(ObjectGuid(guid));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user