Merge pull request #132 from ElunaLuaEngine/dev

Merge Dev changes into Master
This commit is contained in:
Foereaper
2014-12-21 08:14:23 +01:00
16 changed files with 352 additions and 522 deletions

View File

@@ -31,7 +31,7 @@ namespace LuaCorpse
*/
int GetGhostTime(Eluna* /*E*/, lua_State* L, Corpse* corpse)
{
Eluna::Push(L, uint32(corpse->GetGhostTime()));
Eluna::Push(L, corpse->GetGhostTime());
return 1;
}
@@ -59,7 +59,7 @@ namespace LuaCorpse
* Resets the [Corpse] ghost time.
*
*/
int ResetGhostTime(Eluna* /*E*/, lua_State* L, Corpse* corpse)
int ResetGhostTime(Eluna* /*E*/, lua_State* /*L*/, Corpse* corpse)
{
corpse->ResetGhostTime();
return 0;
@@ -69,7 +69,7 @@ namespace LuaCorpse
* Saves the [Corpse] to the database.
*
*/
int SaveToDB(Eluna* /*E*/, lua_State* L, Corpse* corpse)
int SaveToDB(Eluna* /*E*/, lua_State* /*L*/, Corpse* corpse)
{
corpse->SaveToDB();
return 0;
@@ -79,7 +79,7 @@ namespace LuaCorpse
* Deletes the [Corpse] from the world.
*
*/
int DeleteBonesFromWorld(Eluna* /*E*/, lua_State* L, Corpse* corpse)
int DeleteBonesFromWorld(Eluna* /*E*/, lua_State* /*L*/, Corpse* corpse)
{
corpse->DeleteBonesFromWorld();
return 0;

View File

@@ -30,7 +30,8 @@ public:
functionReference(funcRef),
isTemporary(shots != 0),
remainingShots(shots)
{}
{
}
};
typedef std::vector<Binding> FunctionRefVector;
typedef UNORDERED_MAP<int, FunctionRefVector> EventToFunctionsMap;
@@ -49,9 +50,6 @@ public:
// unregisters all registered functions and clears all registered events from the bindings
virtual void Clear() { };
// Updates the counters on all temporary bindings and erases them if the counter would reach 0.
virtual void UpdateTemporaryBindings() { };
};
template<typename T>
@@ -74,35 +72,29 @@ public:
Bindings.clear();
}
void UpdateTemporaryBindings() override
// Pushes the function references and updates the counters on the binds and erases them if the counter would reach 0
void PushFuncRefs(lua_State* L, int event_id)
{
for (EventToFunctionsMap::iterator itr = Bindings.begin(); itr != Bindings.end();)
for (FunctionRefVector::iterator it = Bindings[event_id].begin(); it != Bindings[event_id].end();)
{
for (FunctionRefVector::iterator it = itr->second.begin(); it != itr->second.end();)
{
Binding &b = (*it);
if (b.isTemporary && b.remainingShots == 0)
{
luaL_unref(E.L, LUA_REGISTRYINDEX, b.functionReference);
it = itr->second.erase(it);
}
else
{
it++;
}
}
FunctionRefVector::iterator it_old = it++;
// If there are no more entries in the vector, erase the vector.
if (itr->second.empty())
lua_rawgeti(L, LUA_REGISTRYINDEX, (it_old->functionReference));
if (it_old->isTemporary)
{
itr = Bindings.erase(itr);
}
else
{
itr++;
--it_old->remainingShots;
if (it_old->remainingShots == 0)
{
luaL_unref(L, LUA_REGISTRYINDEX, it_old->functionReference);
Bindings[event_id].erase(it_old);
}
}
}
}
if (Bindings[event_id].empty())
Bindings.erase(event_id);
};
void Insert(int eventId, int funcRef, uint32 shots) // Inserts a new registered event
{
@@ -148,48 +140,32 @@ public:
Bindings.clear();
}
void UpdateTemporaryBindings() override
// Pushes the function references and updates the counters on the binds and erases them if the counter would reach 0
void PushFuncRefs(lua_State* L, int event_id, uint32 entry)
{
for (EntryToEventsMap::iterator itr = Bindings.begin(); itr != Bindings.end();)
for (FunctionRefVector::iterator it = Bindings[entry][event_id].begin(); it != Bindings[entry][event_id].end();)
{
for (EventToFunctionsMap::iterator it = itr->second.begin(); it != itr->second.end();)
{
for (FunctionRefVector::iterator i = it->second.begin(); i != it->second.end();)
{
Binding &b = (*i);
if (b.isTemporary && b.remainingShots == 0)
{
luaL_unref(E.L, LUA_REGISTRYINDEX, b.functionReference);
i = it->second.erase(i);
}
else
{
i++;
}
}
FunctionRefVector::iterator it_old = it++;
// If there are no more entries in the vector, erase the vector.
if (it->second.empty())
{
it = itr->second.erase(it);
}
else
{
it++;
}
}
lua_rawgeti(L, LUA_REGISTRYINDEX, (it_old->functionReference));
// If there are no more vector in the map, erase the map.
if (itr->second.empty())
if (it_old->isTemporary)
{
itr = Bindings.erase(itr);
}
else
{
itr++;
--it_old->remainingShots;
if (it_old->remainingShots == 0)
{
luaL_unref(L, LUA_REGISTRYINDEX, it_old->functionReference);
Bindings[entry][event_id].erase(it_old);
}
}
}
}
if (Bindings[entry][event_id].empty())
Bindings[entry].erase(event_id);
if (Bindings[entry].empty())
Bindings.erase(entry);
};
void Insert(uint32 entryId, int eventId, int funcRef, uint32 shots) // Inserts a new registered event
{

View File

@@ -65,7 +65,6 @@ public:
private:
void RemoveEvents_internal();
void AddEvent(LuaEvent* Event);
bool removeAllEvents;
EventList eventList;
uint64 m_time;
WorldObject* obj;

View File

@@ -425,19 +425,21 @@ public:
return 1;
}
static int Add(lua_State* L) { return 0; }
static int Substract(lua_State* L) { return 0; }
static int Multiply(lua_State* L) { return 0; }
static int Divide(lua_State* L) { return 0; }
static int Mod(lua_State* L) { return 0; }
static int Pow(lua_State* L) { return 0; }
static int UnaryMinus(lua_State* L) { return 0; }
static int Concat(lua_State* L) { return 0; }
static int Length(lua_State* L) { return 0; }
static int Equal(lua_State* L) { return 0; }
static int Less(lua_State* L) { return 0; }
static int LessOrEqual(lua_State* L) { return 0; }
static int Call(lua_State* L) { return 0; }
static int ArithmeticError(lua_State* L) { return luaL_error(L, "attempt to perform arithmetic on a %s value", tname); }
static int CompareError(lua_State* L) { return luaL_error(L, "attempt to compare %s", tname); }
static int Add(lua_State* L) { return ArithmeticError(L); }
static int Substract(lua_State* L) { return ArithmeticError(L); }
static int Multiply(lua_State* L) { return ArithmeticError(L); }
static int Divide(lua_State* L) { return ArithmeticError(L); }
static int Mod(lua_State* L) { return ArithmeticError(L); }
static int Pow(lua_State* L) { return ArithmeticError(L); }
static int UnaryMinus(lua_State* L) { return ArithmeticError(L); }
static int Concat(lua_State* L) { return luaL_error(L, "attempt to concatenate a %s value", tname); }
static int Length(lua_State* L) { return luaL_error(L, "attempt to get length of a %s value", tname); }
static int Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKOBJ<T>(L, 1) == Eluna::CHECKOBJ<T>(L, 2)); return 1; }
static int Less(lua_State* L) { return CompareError(L); }
static int LessOrEqual(lua_State* L) { return CompareError(L); }
static int Call(lua_State* L) { return luaL_error(L, "attempt to call a %s value", tname); }
};
//
//template<typename T> const char* ElunaTemplate<T>::tname;

View File

@@ -113,11 +113,7 @@ namespace LuaGlobalFunctions
*/
int GetGameTime(Eluna* /*E*/, lua_State* L)
{
time_t time = eWorld->GetGameTime();
if (time < 0)
Eluna::Push(L, int32(time));
else
Eluna::Push(L, uint32(time));
Eluna::Push(L, eWorld->GetGameTime());
return 1;
}
@@ -475,47 +471,33 @@ namespace LuaGlobalFunctions
return 1;
}
/**
* Registers a packet event
*
* <pre>
* enum PacketEvents
* {
* PACKET_EVENT_ON_PACKET_RECEIVE = 5,
* PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN = 6,
* PACKET_EVENT_ON_PACKET_SEND = 7,
*
* PACKET_EVENT_COUNT
* };
* </pre>
*
* @param uint32 entry : opcode
* @param uint32 event : packet event Id, refer to PacketEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
*/
int RegisterPacketEvent(Eluna* E, lua_State* L)
void RegisterEntryHelper(Eluna* E, lua_State* L, int regtype)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
luaL_checktype(L, 3, LUA_TFUNCTION);
uint32 shots = Eluna::CHECKVAL<uint32>(L, 4, 0);
lua_pushvalue(L, 3);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_PACKET, entry, ev, functionRef, shots);
return 0;
if (functionRef >= 0)
E->Register(regtype, entry, ev, functionRef, shots);
else
luaL_argerror(L, 3, "unable to make a ref to function");
}
void RegisterEventHelper(Eluna* E, lua_State* L, int regtype)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
luaL_checktype(L, 2, LUA_TFUNCTION);
uint32 shots = Eluna::CHECKVAL<uint32>(L, 3, 0);
lua_pushvalue(L, 2);
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef >= 0)
E->Register(regtype, 0, ev, functionRef, shots);
else
luaL_argerror(L, 2, "unable to make a ref to function");
}
/**
@@ -579,29 +561,12 @@ namespace LuaGlobalFunctions
* </pre>
*
* @param uint32 event : server event Id, refer to ServerEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterServerEvent(Eluna* E, lua_State* L)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
uint32 shots;
if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 2);
}
else // Otherwise, shots is the second argument and the function must be the third.
{
shots = Eluna::CHECKVAL<uint32>(L, 2);
luaL_checktype(L, 3, LUA_TFUNCTION);
lua_pushvalue(L, 3);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_SERVER, 0, ev, functionRef, shots);
RegisterEventHelper(E, L, HookMgr::REGTYPE_SERVER);
return 0;
}
@@ -661,29 +626,12 @@ namespace LuaGlobalFunctions
* </pre>
*
* @param uint32 event : [Player] event Id, refer to PlayerEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterPlayerEvent(Eluna* E, lua_State* L)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
uint32 shots;
if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 2);
}
else // Otherwise, shots is the second argument and the function must be the third.
{
shots = Eluna::CHECKVAL<uint32>(L, 2);
luaL_checktype(L, 3, LUA_TFUNCTION);
lua_pushvalue(L, 3);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_PLAYER, 0, ev, functionRef, shots);
RegisterEventHelper(E, L, HookMgr::REGTYPE_PLAYER);
return 0;
}
@@ -711,29 +659,12 @@ namespace LuaGlobalFunctions
* </pre>
*
* @param uint32 event : [Guild] event Id, refer to GuildEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterGuildEvent(Eluna* E, lua_State* L)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
uint32 shots;
if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 2);
}
else // Otherwise, shots is the second argument and the function must be the third.
{
shots = Eluna::CHECKVAL<uint32>(L, 2);
luaL_checktype(L, 3, LUA_TFUNCTION);
lua_pushvalue(L, 3);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_GUILD, 0, ev, functionRef, shots);
RegisterEventHelper(E, L, HookMgr::REGTYPE_GUILD);
return 0;
}
@@ -756,29 +687,61 @@ namespace LuaGlobalFunctions
* </pre>
*
* @param uint32 event : [Group] event Id, refer to GroupEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterGroupEvent(Eluna* E, lua_State* L)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
uint32 shots;
RegisterEventHelper(E, L, HookMgr::REGTYPE_GROUP);
return 0;
}
if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 2);
}
else // Otherwise, shots is the second argument and the function must be the third.
{
shots = Eluna::CHECKVAL<uint32>(L, 2);
luaL_checktype(L, 3, LUA_TFUNCTION);
lua_pushvalue(L, 3);
}
/**
* Registers a [Battleground] event
*
* <pre>
* enum BGEvents
* {
* BG_EVENT_ON_START = 1, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_ON_END = 2, // (event, bg, bgId, instanceId, winner) - Needs to be added to TC
* BG_EVENT_ON_CREATE = 3, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_ON_PRE_DESTROY = 4, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_COUNT
* };
* </pre>
*
* @param uint32 event : [Battleground] event Id, refer to BGEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterBGEvent(Eluna* E, lua_State* L)
{
RegisterEventHelper(E, L, HookMgr::REGTYPE_BG);
return 0;
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_GROUP, 0, ev, functionRef, shots);
/**
* Registers a packet event
*
* <pre>
* enum PacketEvents
* {
* PACKET_EVENT_ON_PACKET_RECEIVE = 5,
* PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN = 6,
* PACKET_EVENT_ON_PACKET_SEND = 7,
*
* PACKET_EVENT_COUNT
* };
* </pre>
*
* @param uint32 entry : opcode
* @param uint32 event : packet event Id, refer to PacketEvents above
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterPacketEvent(Eluna* E, lua_State* L)
{
RegisterEntryHelper(E, L, HookMgr::REGTYPE_PACKET);
return 0;
}
@@ -796,30 +759,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 menu_id : [Creature] entry Id
* @param uint32 event : [Creature] gossip event Id, refer to GossipEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterCreatureGossipEvent(Eluna* E, lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_CREATURE_GOSSIP, entry, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_CREATURE_GOSSIP);
return 0;
}
@@ -837,30 +782,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 menu_id : [GameObject] entry Id
* @param uint32 event : [GameObject] gossip event Id, refer to GossipEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterGameObjectGossipEvent(Eluna* E, lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_GAMEOBJECT_GOSSIP, entry, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_GAMEOBJECT_GOSSIP);
return 0;
}
@@ -881,30 +808,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 entry : [Item] entry Id
* @param uint32 event : [Item] event Id, refer to ItemEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterItemEvent(Eluna* E, lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_ITEM, entry, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_ITEM);
return 0;
}
@@ -922,30 +831,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 entry : [Item] entry Id
* @param uint32 event : [Item] gossip event Id, refer to GossipEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterItemGossipEvent(Eluna* E, lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_ITEM_GOSSIP, entry, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_ITEM_GOSSIP);
return 0;
}
@@ -963,30 +854,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 menu_id : [Player] gossip menu Id
* @param uint32 event : [Player] gossip event Id, refer to GossipEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterPlayerGossipEvent(Eluna* E, lua_State* L)
{
uint32 menu_id = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_PLAYER_GOSSIP, menu_id, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_PLAYER_GOSSIP);
return 0;
}
@@ -1039,30 +912,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 entry : [Creature] entry Id
* @param uint32 event : [Creature] event Id, refer to CreatureEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterCreatureEvent(Eluna* E, lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_CREATURE, entry, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_CREATURE);
return 0;
}
@@ -1091,71 +946,12 @@ namespace LuaGlobalFunctions
*
* @param uint32 entry : [GameObject] entry Id
* @param uint32 event : [GameObject] event Id, refer to GameObjectEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
*/
int RegisterGameObjectEvent(Eluna* E, lua_State* L)
{
uint32 entry = Eluna::CHECKVAL<uint32>(L, 1);
uint32 ev = Eluna::CHECKVAL<uint32>(L, 2);
uint32 shots;
if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 3);
}
else // Otherwise, shots is the third argument and the function must be the fourth.
{
shots = Eluna::CHECKVAL<uint32>(L, 3);
luaL_checktype(L, 4, LUA_TFUNCTION);
lua_pushvalue(L, 4);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_GAMEOBJECT, entry, ev, functionRef, shots);
return 0;
}
/**
* Registers a [Battleground] event
*
* <pre>
* enum BGEvents
* {
* BG_EVENT_ON_START = 1, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_ON_END = 2, // (event, bg, bgId, instanceId, winner) - Needs to be added to TC
* BG_EVENT_ON_CREATE = 3, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_ON_PRE_DESTROY = 4, // (event, bg, bgId, instanceId) - Needs to be added to TC
* BG_EVENT_COUNT
* };
* </pre>
*
* @param uint32 event : [Battleground] event Id, refer to BGEvents above
* @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function"
* @param function function : function to register
*/
int RegisterBGEvent(Eluna* E, lua_State* L)
{
uint32 ev = Eluna::CHECKVAL<uint32>(L, 1);
uint32 shots;
if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility.
{
shots = 0;
lua_pushvalue(L, 2);
}
else // Otherwise, shots is the second argument and the function must be the third.
{
shots = Eluna::CHECKVAL<uint32>(L, 2);
luaL_checktype(L, 3, LUA_TFUNCTION);
lua_pushvalue(L, 3);
}
int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
if (functionRef > 0)
E->Register(HookMgr::REGTYPE_BG, 0, ev, functionRef, shots);
RegisterEntryHelper(E, L, HookMgr::REGTYPE_GAMEOBJECT);
return 0;
}
@@ -1182,10 +978,10 @@ namespace LuaGlobalFunctions
}
/**
* Executes world database sql [Query] instantly and returns QueryResult object
* Executes an sql to your world database instantly and returns [ElunaQuery]
*
* @param string query : sql [Query] to run
* @return QueryResult result
* @param string sql : sql to run
* @return [ElunaQuery] result
*/
int WorldDBQuery(Eluna* /*E*/, lua_State* L)
{
@@ -1208,9 +1004,9 @@ namespace LuaGlobalFunctions
}
/**
* Executes a sql [Query] (not instantly) to your world database
* Executes an sql to your character database. The SQL is not ran instantly.
*
* @param string query : sql [Query] to execute
* @param string sql : sql [ElunaQuery] to execute
*/
int WorldDBExecute(Eluna* /*E*/, lua_State* L)
{
@@ -1220,10 +1016,10 @@ namespace LuaGlobalFunctions
}
/**
* Executes character database sql [Query] instantly and returns QueryResult object
* Executes an sql to your character database instantly and returns [ElunaQuery]
*
* @param string query : sql [Query] to run
* @return [Query] result
* @param string sql : sql to run
* @return [ElunaQuery] result
*/
int CharDBQuery(Eluna* /*E*/, lua_State* L)
{
@@ -1246,9 +1042,9 @@ namespace LuaGlobalFunctions
}
/**
* Executes a [Query] (not instantly) to your character database
* Executes an sql to your character database. The SQL is not ran instantly.
*
* @param string query : sql [Query] to execute
* @param string sql : sql to run
*/
int CharDBExecute(Eluna* /*E*/, lua_State* L)
{
@@ -1258,10 +1054,10 @@ namespace LuaGlobalFunctions
}
/**
* Executes auth database sql [Query] instantly and returns QueryResult object
* Executes an sql to your auth database instantly and returns [ElunaQuery]
*
* @param string query : sql [Query] to run
* @return [Query] result
* @param string sql : sql to run
* @return [ElunaQuery] result
*/
int AuthDBQuery(Eluna* /*E*/, lua_State* L)
{
@@ -1284,9 +1080,9 @@ namespace LuaGlobalFunctions
}
/**
* Executes a [Query] (not instantly ) to your auth database
* Executes an sql to your auth database. The SQL is not ran instantly.
*
* @param string query : sql [Query] to execute
* @param string sql : sql to run
*/
int AuthDBExecute(Eluna* /*E*/, lua_State* L)
{
@@ -2214,7 +2010,7 @@ namespace LuaGlobalFunctions
* Removes old [Corpse]s from the world
*
*/
int RemoveOldCorpses(Eluna* /*E*/, lua_State* L)
int RemoveOldCorpses(Eluna* /*E*/, lua_State* /*L*/)
{
eObjectAccessor->RemoveOldCorpses();
return 0;
@@ -2493,5 +2289,63 @@ namespace LuaGlobalFunctions
ELUNA_LOG_DEBUG("%s", GetStackAsString(L).c_str());
return 0;
}
/**
* Returns an object represeting long long.
* The value by default is 0, but can be initialized to a value by passing a number or long long as a string.
*
* @proto value = ()
* @proto value = (number)
* @proto value = (longlong)
* @proto value = (longlongstr)
* @param int32 number : regular lua number
* @param int64 longlong : a long long object
* @param string longlongstr : a long long as a string
* @return int64 value
*/
int CreateLongLong(Eluna* /*E*/, lua_State* L)
{
long long init = 0;
if (lua_isstring(L, 1))
{
std::string str = Eluna::CHECKVAL<std::string>(L, 1);
if (sscanf(str.c_str(), SI64FMTD, &init) != 1)
return luaL_argerror(L, 1, "long long (as string) could not be converted");
}
else if (!lua_isnoneornil(L, 1))
init = Eluna::CHECKVAL<long long>(L, 1);
Eluna::Push(L, init);
return 1;
}
/**
* Returns an object represeting unsigned long long.
* The value by default is 0, but can be initialized to a value by passing a number or unsigned long long as a string.
*
* @proto value = ()
* @proto value = (number)
* @proto value = (ulonglong)
* @proto value = (ulonglongstr)
* @param uint32 number : regular lua number
* @param uint64 ulonglong : an unsigned long long object
* @param string ulonglongstr : an unsigned long long as a string
* @return uint64 value
*/
int CreateULongLong(Eluna* /*E*/, lua_State* L)
{
unsigned long long init = 0;
if (lua_isstring(L, 1))
{
std::string str = Eluna::CHECKVAL<std::string>(L, 1);
if (sscanf(str.c_str(), UI64FMTD, &init) != 1)
return luaL_argerror(L, 1, "unsigned long long (as string) could not be converted");
}
else if (!lua_isnoneornil(L, 1))
init = Eluna::CHECKVAL<unsigned long long>(L, 1);
Eluna::Push(L, init);
return 1;
}
}
#endif

View File

@@ -47,21 +47,10 @@ using namespace HookMgr;
if (!BINDMAP->HasEvents(EVENT)) \
RET; \
lua_State* L = this->L; \
ElunaBind* _LuaBind = this->BINDMAP; \
const char* _LuaBindType = this->BINDMAP->groupName; \
uint32 _LuaEvent = EVENT; \
int _LuaStackTop = lua_gettop(L); \
bool _LuaTemporariesDied = false; \
for (size_t i = 0; i < this->BINDMAP->Bindings[_LuaEvent].size(); ++i) \
{ \
if (this->BINDMAP->Bindings[_LuaEvent][i].isTemporary) \
{ \
this->BINDMAP->Bindings[_LuaEvent][i].remainingShots--; \
if (this->BINDMAP->Bindings[_LuaEvent][i].remainingShots == 0) \
_LuaTemporariesDied = true; \
} \
lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[_LuaEvent][i].functionReference)); \
} \
this->BINDMAP->PushFuncRefs(L, _LuaEvent); \
int _LuaFuncTop = lua_gettop(L); \
int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \
Eluna::Push(L, _LuaEvent);
@@ -91,21 +80,10 @@ using namespace HookMgr;
if (!BINDMAP->HasEvents(ENTRY, EVENT)) \
RET; \
lua_State* L = this->L; \
ElunaBind* _LuaBind = this->BINDMAP; \
const char* _LuaBindType = _LuaBind->groupName; \
const char* _LuaBindType = this->BINDMAP->groupName; \
uint32 _LuaEvent = EVENT; \
int _LuaStackTop = lua_gettop(L); \
bool _LuaTemporariesDied = false; \
for (size_t i = 0; i < this->BINDMAP->Bindings[ENTRY][_LuaEvent].size(); ++i) \
{ \
if (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].isTemporary) \
{ \
this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].remainingShots--; \
if (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].remainingShots == 0) \
_LuaTemporariesDied = true; \
} \
lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].functionReference)); \
} \
this->BINDMAP->PushFuncRefs(L, _LuaEvent, ENTRY); \
int _LuaFuncTop = lua_gettop(L); \
int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \
Eluna::Push(L, _LuaEvent);
@@ -141,8 +119,6 @@ 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); \
} \
lua_settop(L, _LuaStackTop); \
if (_LuaTemporariesDied) \
_LuaBind->UpdateTemporaryBindings(); \
if (!this->event_level) \
this->InvalidateObjects(); // Invalidate objects on outermost hook call

View File

@@ -296,7 +296,7 @@ namespace LuaItem
//if (!test.empty())
//{
name += ' ';
name += suffix[(name != temp->Name1) ? locale : DEFAULT_LOCALE];
name += suffix[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)];
/*}*/
}
}

View File

@@ -450,30 +450,30 @@ void Eluna::Push(lua_State* L)
{
lua_pushnil(L);
}
void Eluna::Push(lua_State* L, const uint64 l)
void Eluna::Push(lua_State* L, const long long l)
{
ElunaTemplate<uint64>::Push(L, new uint64(l));
ElunaTemplate<long long>::Push(L, new long long(l));
}
void Eluna::Push(lua_State* L, const int64 l)
void Eluna::Push(lua_State* L, const unsigned long long l)
{
ElunaTemplate<int64>::Push(L, new int64(l));
ElunaTemplate<unsigned long long>::Push(L, new unsigned long long(l));
}
//void Eluna::Push(lua_State* L, const time_t l)
//{
// ElunaTemplate<uint64>::Push(L, new uint64(l));
//}
//void Eluna::Push(lua_State* L, const size_t l)
//{
// ElunaTemplate<int64>::Push(L, new int64(l));
//}
void Eluna::Push(lua_State* L, const uint32 u)
void Eluna::Push(lua_State* L, const long l)
{
lua_pushunsigned(L, u);
Push(L, static_cast<long long>(l));
}
void Eluna::Push(lua_State* L, const int32 i)
void Eluna::Push(lua_State* L, const unsigned long l)
{
Push(L, static_cast<unsigned long long>(l));
}
void Eluna::Push(lua_State* L, const int i)
{
lua_pushinteger(L, i);
}
void Eluna::Push(lua_State* L, const unsigned int u)
{
lua_pushunsigned(L, u);
}
void Eluna::Push(lua_State* L, const double d)
{
lua_pushnumber(L, d);
@@ -486,7 +486,7 @@ void Eluna::Push(lua_State* L, const bool b)
{
lua_pushboolean(L, b);
}
void Eluna::Push(lua_State* L, const std::string str)
void Eluna::Push(lua_State* L, const std::string& str)
{
lua_pushstring(L, str.c_str());
}
@@ -572,29 +572,29 @@ void Eluna::Push(lua_State* L, Object const* obj)
}
}
static int32 CheckIntegerRange(lua_State* L, int narg, int32 min, int32 max)
static int CheckIntegerRange(lua_State* L, int narg, int min, int max)
{
int64 value = static_cast<int64>(luaL_checknumber(L, narg));
double value = luaL_checknumber(L, narg);
char error_buffer[64];
if (value > max)
{
snprintf(error_buffer, 64, "value must be less than or equal to %d", max);
snprintf(error_buffer, 64, "value must be less than or equal to %i", max);
return luaL_argerror(L, narg, error_buffer);
}
if (value < min)
{
snprintf(error_buffer, 64, "value must be greater than or equal to %d", min);
snprintf(error_buffer, 64, "value must be greater than or equal to %i", min);
return luaL_argerror(L, narg, error_buffer);
}
return static_cast<int32>(value);
return static_cast<int>(value);
}
static uint32 CheckUnsignedRange(lua_State* L, int narg, uint32 max)
static unsigned int CheckUnsignedRange(lua_State* L, int narg, unsigned int max)
{
int64 value = static_cast<int64>(luaL_checknumber(L, narg));
double value = luaL_checknumber(L, narg);
char error_buffer[64];
if (value < 0)
@@ -606,7 +606,7 @@ static uint32 CheckUnsignedRange(lua_State* L, int narg, uint32 max)
return luaL_argerror(L, narg, error_buffer);
}
return static_cast<uint32>(value);
return static_cast<unsigned int>(value);
}
template<> bool Eluna::CHECKVAL<bool>(lua_State* L, int narg)
@@ -621,27 +621,27 @@ template<> double Eluna::CHECKVAL<double>(lua_State* L, int narg)
{
return luaL_checknumber(L, narg);
}
template<> int8 Eluna::CHECKVAL<int8>(lua_State* L, int narg)
template<> signed char Eluna::CHECKVAL<signed char>(lua_State* L, int narg)
{
return CheckIntegerRange(L, narg, SCHAR_MIN, SCHAR_MAX);
}
template<> uint8 Eluna::CHECKVAL<uint8>(lua_State* L, int narg)
template<> unsigned char Eluna::CHECKVAL<unsigned char>(lua_State* L, int narg)
{
return CheckUnsignedRange(L, narg, UCHAR_MAX);
}
template<> int16 Eluna::CHECKVAL<int16>(lua_State* L, int narg)
template<> short Eluna::CHECKVAL<short>(lua_State* L, int narg)
{
return CheckIntegerRange(L, narg, SHRT_MIN, SHRT_MAX);
}
template<> uint16 Eluna::CHECKVAL<uint16>(lua_State* L, int narg)
template<> unsigned short Eluna::CHECKVAL<unsigned short>(lua_State* L, int narg)
{
return CheckUnsignedRange(L, narg, USHRT_MAX);
}
template<> int32 Eluna::CHECKVAL<int32>(lua_State* L, int narg)
template<> int Eluna::CHECKVAL<int>(lua_State* L, int narg)
{
return CheckIntegerRange(L, narg, INT_MIN, INT_MAX);
}
template<> uint32 Eluna::CHECKVAL<uint32>(lua_State* L, int narg)
template<> unsigned int Eluna::CHECKVAL<unsigned int>(lua_State* L, int narg)
{
return CheckUnsignedRange(L, narg, UINT_MAX);
}
@@ -653,30 +653,26 @@ template<> std::string Eluna::CHECKVAL<std::string>(lua_State* L, int narg)
{
return luaL_checkstring(L, narg);
}
template<> int64 Eluna::CHECKVAL<int64>(lua_State* L, int narg)
template<> long long Eluna::CHECKVAL<long long>(lua_State* L, int narg)
{
if (lua_isnumber(L, narg))
return static_cast<int64>(CHECKVAL<double>(L, narg));
return *(Eluna::CHECKOBJ<int64>(L, narg, true));
return static_cast<long long>(CHECKVAL<double>(L, narg));
return *(Eluna::CHECKOBJ<long long>(L, narg, true));
}
template<> uint64 Eluna::CHECKVAL<uint64>(lua_State* L, int narg)
template<> unsigned long long Eluna::CHECKVAL<unsigned long long>(lua_State* L, int narg)
{
if (lua_isnumber(L, narg))
return static_cast<uint64>(CHECKVAL<uint32>(L, narg));
return *(Eluna::CHECKOBJ<uint64>(L, narg, true));
return static_cast<unsigned long long>(CHECKVAL<uint32>(L, narg));
return *(Eluna::CHECKOBJ<unsigned long long>(L, narg, true));
}
template<> long Eluna::CHECKVAL<long>(lua_State* L, int narg)
{
return static_cast<long>(CHECKVAL<long long>(L, narg));
}
template<> unsigned long Eluna::CHECKVAL<unsigned long>(lua_State* L, int narg)
{
return static_cast<unsigned long>(CHECKVAL<unsigned long long>(L, narg));
}
//template<> time_t Eluna::CHECKVAL<time_t>(lua_State* L, int narg)
//{
// if (lua_isnumber(L, narg))
// return static_cast<time_t>(CHECKVAL<double>(L, narg));
// return static_cast<time_t>(*(Eluna::CHECKOBJ<int64>(L, narg, true)));
//}
//template<> size_t Eluna::CHECKVAL<size_t>(lua_State* L, int narg)
//{
// if (lua_isnumber(L, narg))
// return static_cast<size_t>(CHECKVAL<uint32>(L, narg));
// return static_cast<size_t>(*(Eluna::CHECKOBJ<uint64>(L, narg, true)));
//}
template<> Object* Eluna::CHECKOBJ<Object>(lua_State* L, int narg, bool error)
{
@@ -684,7 +680,7 @@ template<> Object* Eluna::CHECKOBJ<Object>(lua_State* L, int narg, bool error)
if (!obj)
obj = CHECKOBJ<Item>(L, narg, false);
if (!obj)
obj = ElunaTemplate<Object>::Check(L, narg, false);
obj = ElunaTemplate<Object>::Check(L, narg, error);
return obj;
}
template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* L, int narg, bool error)
@@ -695,7 +691,7 @@ template<> WorldObject* Eluna::CHECKOBJ<WorldObject>(lua_State* L, int narg, boo
if (!obj)
obj = CHECKOBJ<Corpse>(L, narg, false);
if (!obj)
obj = ElunaTemplate<WorldObject>::Check(L, narg, false);
obj = ElunaTemplate<WorldObject>::Check(L, narg, error);
return obj;
}
template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* L, int narg, bool error)
@@ -704,7 +700,7 @@ template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* L, int narg, bool error)
if (!obj)
obj = CHECKOBJ<Creature>(L, narg, false);
if (!obj)
obj = ElunaTemplate<Unit>::Check(L, narg, false);
obj = ElunaTemplate<Unit>::Check(L, narg, error);
return obj;
}

View File

@@ -160,15 +160,17 @@ public:
// Pushes
static void Push(lua_State* L); // nil
static void Push(lua_State* L, const uint64);
static void Push(lua_State* L, const int64);
static void Push(lua_State* L, const uint32);
static void Push(lua_State* L, const int32);
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*);
static void Push(lua_State* L, const std::string);
template<typename T> static void Push(lua_State* L, T const* ptr)
{
ElunaTemplate<T>::Push(L, ptr);

View File

@@ -127,6 +127,8 @@ ElunaGlobal::ElunaRegister GlobalMethods[] =
{ "AddWeather", &LuaGlobalFunctions::AddWeather },
{ "RemoveWeather", &LuaGlobalFunctions::RemoveWeather },
{ "SendFineWeatherToPlayer", &LuaGlobalFunctions::SendFineWeatherToPlayer },
{ "CreateInt64", &LuaGlobalFunctions::CreateLongLong },
{ "CreateUint64", &LuaGlobalFunctions::CreateULongLong },
{ NULL, NULL },
};
@@ -1269,38 +1271,46 @@ template<> int ElunaTemplate<Vehicle>::CollectGarbage(lua_State* L)
#endif
// Template by Mud from http://stackoverflow.com/questions/4484437/lua-integer-type/4485511#4485511
template<> int ElunaTemplate<uint64>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) + Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) - Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) * Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) / Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) % Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Pow(lua_State* L) { Eluna::Push(L, pow(Eluna::CHECKVAL<uint64>(L, 1), Eluna::CHECKVAL<uint64>(L, 2))); return 1; }
// template<> int ElunaTemplate<uint64>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<uint64>(L, 1)); return 1; }
template<> int ElunaTemplate<uint64>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) == Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) < Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<uint64>(L, 1) <= Eluna::CHECKVAL<uint64>(L, 2)); return 1; }
template<> int ElunaTemplate<uint64>::ToString(lua_State* L)
template<> int ElunaTemplate<unsigned long long>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) + Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) - Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) * Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) / Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) % Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
// template<> int ElunaTemplate<unsigned long long>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<unsigned long long>(L, 1)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) == Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) < Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<unsigned long long>(L, 1) <= Eluna::CHECKVAL<unsigned long long>(L, 2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Pow(lua_State* L)
{
uint64 l = Eluna::CHECKVAL<uint64>(L, 1);
Eluna::Push(L, static_cast<unsigned long long>(powl(static_cast<long double>(Eluna::CHECKVAL<unsigned long long>(L, 1)), static_cast<long double>(Eluna::CHECKVAL<unsigned long long>(L, 2)))));
return 1;
}
template<> int ElunaTemplate<unsigned long long>::ToString(lua_State* L)
{
unsigned long long l = Eluna::CHECKVAL<unsigned long long>(L, 1);
std::ostringstream ss;
ss << l;
Eluna::Push(L, ss.str());
return 1;
}
template<> int ElunaTemplate<int64>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) + Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) - Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) * Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) / Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) % Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Pow(lua_State* L) { Eluna::Push(L, pow(Eluna::CHECKVAL<int64>(L, 1), Eluna::CHECKVAL<int64>(L, 2))); return 1; }
template<> int ElunaTemplate<int64>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<int64>(L, 1)); return 1; }
template<> int ElunaTemplate<int64>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) == Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) < Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<int64>(L, 1) <= Eluna::CHECKVAL<int64>(L, 2)); return 1; }
template<> int ElunaTemplate<int64>::ToString(lua_State* L)
template<> int ElunaTemplate<long long>::Add(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) + Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Substract(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) - Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Multiply(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) * Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Divide(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) / Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Mod(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) % Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::UnaryMinus(lua_State* L) { Eluna::Push(L, -Eluna::CHECKVAL<long long>(L, 1)); return 1; }
template<> int ElunaTemplate<long long>::Equal(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) == Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Less(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) < Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::LessOrEqual(lua_State* L) { Eluna::Push(L, Eluna::CHECKVAL<long long>(L, 1) <= Eluna::CHECKVAL<long long>(L, 2)); return 1; }
template<> int ElunaTemplate<long long>::Pow(lua_State* L)
{
int64 l = Eluna::CHECKVAL<int64>(L, 1);
Eluna::Push(L, static_cast<long long>(powl(static_cast<long double>(Eluna::CHECKVAL<long long>(L, 1)), static_cast<long double>(Eluna::CHECKVAL<long long>(L, 2)))));
return 1;
}
template<> int ElunaTemplate<long long>::ToString(lua_State* L)
{
long long l = Eluna::CHECKVAL<long long>(L, 1);
std::ostringstream ss;
ss << l;
Eluna::Push(L, ss.str());
@@ -1389,7 +1399,7 @@ void RegisterFunctions(Eluna* E)
ElunaTemplate<ElunaQuery>::Register(E, "ElunaQuery", true);
ElunaTemplate<ElunaQuery>::SetMethods(E, QueryMethods);
ElunaTemplate<uint64>::Register(E, "uint64", true);
ElunaTemplate<long long>::Register(E, "long long", true);
ElunaTemplate<int64>::Register(E, "int64", true);
ElunaTemplate<unsigned long long>::Register(E, "unsigned long long", true);
}

View File

@@ -1317,7 +1317,7 @@ namespace LuaPlayer
/* OTHER */
#if (!defined(TBC) && !defined(CLASSIC))
int ResetPetTalents(Eluna* /*E*/, lua_State* L, Player* player)
int ResetPetTalents(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifndef TRINITY
Pet* pet = player->GetPet();
@@ -1331,7 +1331,7 @@ namespace LuaPlayer
return 0;
}
int ResetAchievements(Eluna* /*E*/, lua_State* L, Player* player)
int ResetAchievements(Eluna* /*E*/, lua_State* /*L*/, Player* player)
{
#ifndef TRINITY
player->GetAchievementMgr().Reset();

View File

@@ -1248,7 +1248,7 @@ namespace LuaUnit
}*/
/* OTHER */
int ClearThreatList(Eluna* /*E*/, lua_State* L, Unit* unit)
int ClearThreatList(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
#ifdef MANGOS
unit->GetThreatManager().clearReferences();
@@ -1266,7 +1266,7 @@ namespace LuaUnit
return 0;
}
int Dismount(Eluna* /*E*/, lua_State* L, Unit* unit)
int Dismount(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
if (unit->IsMounted())
{
@@ -1329,7 +1329,7 @@ namespace LuaUnit
// unit->GetMotionMaster()->Clear(); // all
// }
int MoveStop(Eluna* /*E*/, lua_State* L, Unit* unit)
int MoveStop(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->StopMoving();
return 0;
@@ -1349,7 +1349,7 @@ namespace LuaUnit
return 0;
}
int MoveIdle(Eluna* /*E*/, lua_State* L, Unit* unit)
int MoveIdle(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->GetMotionMaster()->MoveIdle();
return 0;
@@ -1368,7 +1368,7 @@ namespace LuaUnit
return 0;
}
int MoveHome(Eluna* /*E*/, lua_State* L, Unit* unit)
int MoveHome(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->GetMotionMaster()->MoveTargetedHome();
return 0;
@@ -1392,7 +1392,7 @@ namespace LuaUnit
return 0;
}
int MoveConfused(Eluna* /*E*/, lua_State* L, Unit* unit)
int MoveConfused(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->GetMotionMaster()->MoveConfused();
return 0;
@@ -1486,7 +1486,7 @@ namespace LuaUnit
return 0;
}
int DeMorph(Eluna* /*E*/, lua_State* L, Unit* unit)
int DeMorph(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->DeMorph();
return 0;
@@ -1547,7 +1547,7 @@ namespace LuaUnit
return 0;
}
int ClearInCombat(Eluna* /*E*/, lua_State* L, Unit* unit)
int ClearInCombat(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->ClearInCombat();
return 0;
@@ -1627,7 +1627,7 @@ namespace LuaUnit
return 0;
}
int RemoveAllAuras(Eluna* /*E*/, lua_State* L, Unit* unit)
int RemoveAllAuras(Eluna* /*E*/, lua_State* /*L*/, Unit* unit)
{
unit->RemoveAllAuras();
return 0;

View File

@@ -653,7 +653,7 @@ namespace LuaWorldObject
* Removes all timed events from a [WorldObject]
*
*/
int RemoveEvents(Eluna* /*E*/, lua_State* L, WorldObject* obj)
int RemoveEvents(Eluna* /*E*/, lua_State* /*L*/, WorldObject* obj)
{
obj->elunaEvents->RemoveEvents();
return 0;

View File

@@ -43,7 +43,10 @@ This is a template for a function that takes in different parameters. When defin
*
* @proto returnValue = (object)
* @proto returnValue = (x, y, z)
* @param Type paramName = defaultValue : parameter description
* @param [WorldObject] object = defaultValue : parameter description
* @param float x = defaultValue : parameter description
* @param float y = defaultValue : parameter description
* @param float z = defaultValue : parameter description
* @return Type returnName : return value description
*/
```

View File

@@ -118,6 +118,7 @@ if __name__ == '__main__':
'string': 'http://www.lua.org/pil/2.4.html',
'table': 'http://www.lua.org/pil/2.5.html',
'function': 'http://www.lua.org/pil/2.6.html',
'...': 'http://www.lua.org/pil/5.2.html',
}
def data_type_parser(content):
@@ -132,6 +133,8 @@ if __name__ == '__main__':
url = '{}{}/index.html'.format(('../' * level), class_name)
return '<strong><a class="mod" href="{}">{}</a></strong>'.format(url, class_name)
return content[1:-1]
return link_parser, data_type_parser
# Create the render function with the template path and parser maker.

View File

@@ -18,6 +18,8 @@ class ParameterDoc(object):
'uint16': ('0', '65,535'),
'int32': ('-2,147,483,647', '2,147,483,647'),
'uint32': ('0', '4,294,967,295'),
'int64': ('-9,223,372,036,854,775,808', '9,223,372,036,854,775,807'),
'uint64': ('0', '18,446,744,073,709,551,615'),
}
@params(self=object, name=unicode, data_type=str, description=unicode, default_value=Nullable(unicode))
@@ -47,8 +49,8 @@ class ParameterDoc(object):
elif self.data_type == 'bool':
self.data_type = 'boolean'
elif self.data_type == 'uint64' or self.data_type == 'int64':
self.data_type = 'string'
elif self.data_type == 'int64' or self.data_type == 'uint64':
self.data_type = '[' + self.data_type + ']'
class MethodDoc(object):
@@ -112,7 +114,7 @@ class ClassParser(object):
# An extra optional space (\s?) was thrown in to make it different from `class_body_regex`.
param_regex = re.compile(r"""\s*\*\s@param\s # The @param tag starts with opt. whitespace followed by "* @param ".
([\[\]\w]+)\s(\w+) # The data type, a space, and the name of the param.
([^\s]+)\s(\w+) # The data type, a space, and the name of the param.
(?:\s=\s(\w+))? # The default value: a = surrounded by spaces, followed by text.
(?:\s:\s(.+))? # The description: a colon surrounded by spaces, followed by text.
""", re.X)
@@ -183,11 +185,18 @@ class ClassParser(object):
if parameters != '':
parameters = ' ' + parameters + ' '
if self.returned:
return_values = ', '.join([param.name for param in self.returned])
prototype = '{0} = {1}:{2}({3})'.format(return_values, self.class_name, self.method_name, parameters)
if self.class_name == 'Global':
if self.returned:
return_values = ', '.join([param.name for param in self.returned])
prototype = '{0} = {1}({2})'.format(return_values, self.method_name, parameters)
else:
prototype = '{0}({1})'.format(self.method_name, parameters)
else:
prototype = '{0}:{1}({2})'.format(self.class_name, self.method_name, parameters)
if self.returned:
return_values = ', '.join([param.name for param in self.returned])
prototype = '{0} = {1}:{2}({3})'.format(return_values, self.class_name, self.method_name, parameters)
else:
prototype = '{0}:{1}({2})'.format(self.class_name, self.method_name, parameters)
self.prototypes.append(prototype)
else: