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

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