diff --git a/ElunaTemplate.cpp b/ElunaTemplate.cpp new file mode 100644 index 0000000000..2a9a4fff82 --- /dev/null +++ b/ElunaTemplate.cpp @@ -0,0 +1,87 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// Eluna +#include "LuaEngine.h" +#include "ElunaIncludes.h" +#include "ElunaTemplate.h" +#include "ElunaUtility.h" + +#if defined TRACKABLE_PTR_NAMESPACE +ElunaConstrainedObjectRef GetWeakPtrFor(Aura const* obj) +{ +#if defined ELUNA_TRINITY + Map* map = obj->GetOwner()->GetMap(); +#elif defined ELUNA_CMANGOS + Map* map = obj->GetTarget()->GetMap(); +#endif + return { obj->GetWeakPtr(), map }; +} +ElunaConstrainedObjectRef GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; } +ElunaConstrainedObjectRef GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; } +ElunaConstrainedObjectRef GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; } +ElunaConstrainedObjectRef GetWeakPtrFor(Map const* obj) { return { obj->GetWeakPtr(), obj }; } +ElunaConstrainedObjectRef GetWeakPtrForObjectImpl(Object const* obj) +{ + if (obj->isType(TYPEMASK_WORLDOBJECT)) + return { obj->GetWeakPtr(), static_cast(obj)->GetMap() }; + + if (obj->GetTypeId() == TYPEID_ITEM) + if (Player const* player = static_cast(obj)->GetOwner()) + return { obj->GetWeakPtr(), player->GetMap() }; + + // possibly dangerous item + return { obj->GetWeakPtr(), nullptr }; +} +ElunaConstrainedObjectRef GetWeakPtrFor(Quest const* obj) { return { obj->GetWeakPtr(), nullptr }; } +ElunaConstrainedObjectRef GetWeakPtrFor(Spell const* obj) { return { obj->GetWeakPtr(), obj->GetCaster()->GetMap() }; } +#if ELUNA_EXPANSION >= EXP_WOTLK +ElunaConstrainedObjectRef GetWeakPtrFor(Vehicle const* obj) +{ +#if defined ELUNA_TRINITY + Map* map = obj->GetBase()->GetMap(); +#elif defined ELUNA_CMANGOS + Map* map = obj->GetOwner()->GetMap(); +#endif + return { obj->GetWeakPtr(), map }; +} +#endif +#endif + +template<> inline int ElunaTemplate::Add(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::plus()); } +template<> inline int ElunaTemplate::Subtract(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::minus()); } +template<> inline int ElunaTemplate::Multiply(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::multiplies()); } +template<> inline int ElunaTemplate::Divide(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::divides()); } +template<> inline int ElunaTemplate::Mod(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::modulus()); } +template<> inline int ElunaTemplate::Equal(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::equal_to()); } +template<> inline int ElunaTemplate::Less(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less()); } +template<> inline int ElunaTemplate::LessOrEqual(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less_equal()); } +template<> inline int ElunaTemplate::ToString(lua_State* L) { return ElunaTemplateHelper::ToString(L); } +template<> inline int ElunaTemplate::Pow(lua_State* L) { return ElunaTemplateHelper::Pow(L); } + +template<> inline int ElunaTemplate::Add(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::plus()); } +template<> inline int ElunaTemplate::Subtract(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::minus()); } +template<> inline int ElunaTemplate::Multiply(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::multiplies()); } +template<> inline int ElunaTemplate::Divide(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::divides()); } +template<> inline int ElunaTemplate::Mod(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::modulus()); } +template<> inline int ElunaTemplate::UnaryMinus(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::negate()); } +template<> inline int ElunaTemplate::Equal(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::equal_to()); } +template<> inline int ElunaTemplate::Less(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less()); } +template<> inline int ElunaTemplate::LessOrEqual(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less_equal()); } +template<> inline int ElunaTemplate::ToString(lua_State* L) { return ElunaTemplateHelper::ToString(L); } +template<> inline int ElunaTemplate::Pow(lua_State* L) { return ElunaTemplateHelper::Pow(L); } + +template<> inline int ElunaTemplate::Equal(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL(1) == E->CHECKVAL(2)); return 1; } +template<> inline int ElunaTemplate::ToString(lua_State* L) +{ + Eluna* E = Eluna::GetEluna(L); +#if defined ELUNA_TRINITY + E->Push(E->CHECKVAL(1).ToString()); +#else + E->Push(E->CHECKVAL(1).GetString()); +#endif + return 1; +} diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 6e29252662..5a9ce56ca6 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -27,7 +27,7 @@ extern "C" // Additional lua libraries }; -extern void RegisterFunctions(Eluna* E); +extern void RegisterMethods(Eluna* E); void Eluna::_ReloadEluna() { @@ -146,7 +146,7 @@ void Eluna::OpenLua() luaL_openlibs(L); // Register methods and functions - RegisterFunctions(this); + RegisterMethods(this); // get require paths const std::string& requirepath = sElunaLoader->GetRequirePath(); diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp deleted file mode 100644 index d44e7d161f..0000000000 --- a/LuaFunctions.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -// Eluna -#include "LuaEngine.h" -#include "ElunaEventMgr.h" -#include "ElunaIncludes.h" -#include "ElunaTemplate.h" -#include "ElunaUtility.h" - -// Method includes -#include "GlobalMethods.h" -#include "ObjectMethods.h" -#include "WorldObjectMethods.h" -#include "UnitMethods.h" -#include "PlayerMethods.h" -#include "CreatureMethods.h" -#include "GroupMethods.h" -#include "GuildMethods.h" -#include "GameObjectMethods.h" -#include "ElunaQueryMethods.h" -#include "AuraMethods.h" -#include "ItemMethods.h" -#include "WorldPacketMethods.h" -#include "SpellMethods.h" -#include "QuestMethods.h" -#include "MapMethods.h" -#include "CorpseMethods.h" -#include "VehicleMethods.h" -#include "BattleGroundMethods.h" - -#if defined TRACKABLE_PTR_NAMESPACE -ElunaConstrainedObjectRef GetWeakPtrFor(Aura const* obj) -{ -#if defined ELUNA_TRINITY - Map* map = obj->GetOwner()->GetMap(); -#elif defined ELUNA_CMANGOS - Map* map = obj->GetTarget()->GetMap(); -#endif - return { obj->GetWeakPtr(), map }; -} -ElunaConstrainedObjectRef GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; } -ElunaConstrainedObjectRef GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; } -ElunaConstrainedObjectRef GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; } -ElunaConstrainedObjectRef GetWeakPtrFor(Map const* obj) { return { obj->GetWeakPtr(), obj }; } -ElunaConstrainedObjectRef GetWeakPtrForObjectImpl(Object const* obj) -{ - if (obj->isType(TYPEMASK_WORLDOBJECT)) - return { obj->GetWeakPtr(), static_cast(obj)->GetMap() }; - - if (obj->GetTypeId() == TYPEID_ITEM) - if (Player const* player = static_cast(obj)->GetOwner()) - return { obj->GetWeakPtr(), player->GetMap() }; - - // possibly dangerous item - return { obj->GetWeakPtr(), nullptr }; -} -ElunaConstrainedObjectRef GetWeakPtrFor(Quest const* obj) { return { obj->GetWeakPtr(), nullptr }; } -ElunaConstrainedObjectRef GetWeakPtrFor(Spell const* obj) { return { obj->GetWeakPtr(), obj->GetCaster()->GetMap() }; } -#if ELUNA_EXPANSION >= EXP_WOTLK -ElunaConstrainedObjectRef GetWeakPtrFor(Vehicle const* obj) -{ -#if defined ELUNA_TRINITY - Map* map = obj->GetBase()->GetMap(); -#elif defined ELUNA_CMANGOS - Map* map = obj->GetOwner()->GetMap(); -#endif - return { obj->GetWeakPtr(), map }; -} -#endif -#endif - -template<> int ElunaTemplate::Add(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::plus()); } -template<> int ElunaTemplate::Subtract(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::minus()); } -template<> int ElunaTemplate::Multiply(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::multiplies()); } -template<> int ElunaTemplate::Divide(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::divides()); } -template<> int ElunaTemplate::Mod(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::modulus()); } -template<> int ElunaTemplate::Equal(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::equal_to()); } -template<> int ElunaTemplate::Less(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less()); } -template<> int ElunaTemplate::LessOrEqual(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less_equal()); } -template<> int ElunaTemplate::ToString(lua_State* L) { return ElunaTemplateHelper::ToString(L); } -template<> int ElunaTemplate::Pow(lua_State* L) { return ElunaTemplateHelper::Pow(L); } - -template<> int ElunaTemplate::Add(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::plus()); } -template<> int ElunaTemplate::Subtract(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::minus()); } -template<> int ElunaTemplate::Multiply(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::multiplies()); } -template<> int ElunaTemplate::Divide(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::divides()); } -template<> int ElunaTemplate::Mod(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::modulus()); } -template<> int ElunaTemplate::UnaryMinus(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::negate()); } -template<> int ElunaTemplate::Equal(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::equal_to()); } -template<> int ElunaTemplate::Less(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less()); } -template<> int ElunaTemplate::LessOrEqual(lua_State* L) { return ElunaTemplateHelper::PerformOp(L, std::less_equal()); } -template<> int ElunaTemplate::ToString(lua_State* L) { return ElunaTemplateHelper::ToString(L); } -template<> int ElunaTemplate::Pow(lua_State* L) { return ElunaTemplateHelper::Pow(L); } - -template<> int ElunaTemplate::Equal(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL(1) == E->CHECKVAL(2)); return 1; } -template<> int ElunaTemplate::ToString(lua_State* L) -{ - Eluna* E = Eluna::GetEluna(L); -#if defined ELUNA_TRINITY - E->Push(E->CHECKVAL(1).ToString()); -#else - E->Push(E->CHECKVAL(1).GetString()); -#endif - return 1; -} - -void RegisterFunctions(Eluna* E) -{ - ElunaTemplate<>::SetMethods(E, LuaGlobalFunctions::GlobalMethods); - - ElunaTemplate::Register(E, "Object"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - - ElunaTemplate::Register(E, "WorldObject"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); - - ElunaTemplate::Register(E, "Unit"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); - ElunaTemplate::SetMethods(E, LuaUnit::UnitMethods); - - ElunaTemplate::Register(E, "Player"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); - ElunaTemplate::SetMethods(E, LuaUnit::UnitMethods); - ElunaTemplate::SetMethods(E, LuaPlayer::PlayerMethods); - - ElunaTemplate::Register(E, "Creature"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); - ElunaTemplate::SetMethods(E, LuaUnit::UnitMethods); - ElunaTemplate::SetMethods(E, LuaCreature::CreatureMethods); - - ElunaTemplate::Register(E, "GameObject"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); - ElunaTemplate::SetMethods(E, LuaGameObject::GameObjectMethods); - - ElunaTemplate::Register(E, "Corpse"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); - ElunaTemplate::SetMethods(E, LuaCorpse::CorpseMethods); - - ElunaTemplate::Register(E, "Item"); - ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); - ElunaTemplate::SetMethods(E, LuaItem::ItemMethods); - -#if ELUNA_EXPANSION >= EXP_WOTLK - ElunaTemplate::Register(E, "Vehicle"); - ElunaTemplate::SetMethods(E, LuaVehicle::VehicleMethods); -#endif - - ElunaTemplate::Register(E, "Group"); - ElunaTemplate::SetMethods(E, LuaGroup::GroupMethods); - - ElunaTemplate::Register(E, "Guild"); - ElunaTemplate::SetMethods(E, LuaGuild::GuildMethods); - - ElunaTemplate::Register(E, "Aura"); - ElunaTemplate::SetMethods(E, LuaAura::AuraMethods); - - ElunaTemplate::Register(E, "Spell"); - ElunaTemplate::SetMethods(E, LuaSpell::SpellMethods); - - ElunaTemplate::Register(E, "Quest"); - ElunaTemplate::SetMethods(E, LuaQuest::QuestMethods); - - ElunaTemplate::Register(E, "Map"); - ElunaTemplate::SetMethods(E, LuaMap::MapMethods); - - ElunaTemplate::Register(E, "BattleGround"); - ElunaTemplate::SetMethods(E, LuaBattleGround::BattleGroundMethods); - - ElunaTemplate::Register(E, "WorldPacket"); - ElunaTemplate::SetMethods(E, LuaPacket::PacketMethods); - - ElunaTemplate::Register(E, "ElunaQuery"); - ElunaTemplate::SetMethods(E, LuaQuery::QueryMethods); - - ElunaTemplate::Register(E, "long long"); - - ElunaTemplate::Register(E, "unsigned long long"); - - ElunaTemplate::Register(E, "ObjectGuid"); - - LuaVal::Register(E->L); -} diff --git a/methods/CMangos/CustomMethods.h b/methods/CMangos/CustomMethods.h new file mode 100644 index 0000000000..346bdddb22 --- /dev/null +++ b/methods/CMangos/CustomMethods.h @@ -0,0 +1,27 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// This file is used for custom Lua methods, without needing to edit the existing method header files. +// This can also be used to override default methods without needing to edit existing methods. +// It follows the same structure as any other method header, except you can use RegisterCustomFunction +// to register multiple method tables in a single file. + +#include "ElunaTemplate.h" +#include "ElunaIncludes.h" + +#ifndef CUSTOMMETHODS_H +#define CUSTOMMETHODS_H + +namespace LuaCustom +{ + // See the CustomMethods header file in the TC method directory for an example. + inline void RegisterCustomMethods([[maybe_unused]] Eluna* E) + { + + }; +}; + +#endif diff --git a/methods/Mangos/CustomMethods.h b/methods/Mangos/CustomMethods.h new file mode 100644 index 0000000000..346bdddb22 --- /dev/null +++ b/methods/Mangos/CustomMethods.h @@ -0,0 +1,27 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// This file is used for custom Lua methods, without needing to edit the existing method header files. +// This can also be used to override default methods without needing to edit existing methods. +// It follows the same structure as any other method header, except you can use RegisterCustomFunction +// to register multiple method tables in a single file. + +#include "ElunaTemplate.h" +#include "ElunaIncludes.h" + +#ifndef CUSTOMMETHODS_H +#define CUSTOMMETHODS_H + +namespace LuaCustom +{ + // See the CustomMethods header file in the TC method directory for an example. + inline void RegisterCustomMethods([[maybe_unused]] Eluna* E) + { + + }; +}; + +#endif diff --git a/methods/Methods.cpp b/methods/Methods.cpp new file mode 100644 index 0000000000..e1ecbab926 --- /dev/null +++ b/methods/Methods.cpp @@ -0,0 +1,122 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// Eluna +#include "LuaEngine.h" +#include "ElunaEventMgr.h" +#include "ElunaIncludes.h" +#include "ElunaTemplate.h" +#include "ElunaUtility.h" + +// Method includes +#include "GlobalMethods.h" +#include "ObjectMethods.h" +#include "WorldObjectMethods.h" +#include "UnitMethods.h" +#include "PlayerMethods.h" +#include "CreatureMethods.h" +#include "GroupMethods.h" +#include "GuildMethods.h" +#include "GameObjectMethods.h" +#include "ElunaQueryMethods.h" +#include "AuraMethods.h" +#include "ItemMethods.h" +#include "WorldPacketMethods.h" +#include "SpellMethods.h" +#include "QuestMethods.h" +#include "MapMethods.h" +#include "CorpseMethods.h" +#include "VehicleMethods.h" +#include "BattleGroundMethods.h" + +// Custom methods +#include "CustomMethods.h" + +void RegisterMethods(Eluna* E) +{ + ElunaTemplate<>::SetMethods(E, LuaGlobalFunctions::GlobalMethods); + + ElunaTemplate::Register(E, "Object"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + + ElunaTemplate::Register(E, "WorldObject"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); + + ElunaTemplate::Register(E, "Unit"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); + ElunaTemplate::SetMethods(E, LuaUnit::UnitMethods); + + ElunaTemplate::Register(E, "Player"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); + ElunaTemplate::SetMethods(E, LuaUnit::UnitMethods); + ElunaTemplate::SetMethods(E, LuaPlayer::PlayerMethods); + + ElunaTemplate::Register(E, "Creature"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); + ElunaTemplate::SetMethods(E, LuaUnit::UnitMethods); + ElunaTemplate::SetMethods(E, LuaCreature::CreatureMethods); + + ElunaTemplate::Register(E, "GameObject"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); + ElunaTemplate::SetMethods(E, LuaGameObject::GameObjectMethods); + + ElunaTemplate::Register(E, "Corpse"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaWorldObject::WorldObjectMethods); + ElunaTemplate::SetMethods(E, LuaCorpse::CorpseMethods); + + ElunaTemplate::Register(E, "Item"); + ElunaTemplate::SetMethods(E, LuaObject::ObjectMethods); + ElunaTemplate::SetMethods(E, LuaItem::ItemMethods); + +#if ELUNA_EXPANSION >= EXP_WOTLK + ElunaTemplate::Register(E, "Vehicle"); + ElunaTemplate::SetMethods(E, LuaVehicle::VehicleMethods); +#endif + + ElunaTemplate::Register(E, "Group"); + ElunaTemplate::SetMethods(E, LuaGroup::GroupMethods); + + ElunaTemplate::Register(E, "Guild"); + ElunaTemplate::SetMethods(E, LuaGuild::GuildMethods); + + ElunaTemplate::Register(E, "Aura"); + ElunaTemplate::SetMethods(E, LuaAura::AuraMethods); + + ElunaTemplate::Register(E, "Spell"); + ElunaTemplate::SetMethods(E, LuaSpell::SpellMethods); + + ElunaTemplate::Register(E, "Quest"); + ElunaTemplate::SetMethods(E, LuaQuest::QuestMethods); + + ElunaTemplate::Register(E, "Map"); + ElunaTemplate::SetMethods(E, LuaMap::MapMethods); + + ElunaTemplate::Register(E, "BattleGround"); + ElunaTemplate::SetMethods(E, LuaBattleGround::BattleGroundMethods); + + ElunaTemplate::Register(E, "WorldPacket"); + ElunaTemplate::SetMethods(E, LuaPacket::PacketMethods); + + ElunaTemplate::Register(E, "ElunaQuery"); + ElunaTemplate::SetMethods(E, LuaQuery::QueryMethods); + + ElunaTemplate::Register(E, "long long"); + + ElunaTemplate::Register(E, "unsigned long long"); + + ElunaTemplate::Register(E, "ObjectGuid"); + + // Register custom methods + LuaCustom::RegisterCustomMethods(E); + + LuaVal::Register(E->L); +} diff --git a/methods/TrinityCore/CustomMethods.h b/methods/TrinityCore/CustomMethods.h new file mode 100644 index 0000000000..0689e1e005 --- /dev/null +++ b/methods/TrinityCore/CustomMethods.h @@ -0,0 +1,41 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// This file is used for custom Lua methods, without needing to edit the existing method header files. +// This can also be used to override default methods without needing to edit existing methods. +// It follows the same structure as any other method header, except you can use RegisterCustomFunction +// to register multiple method tables in a single file. + +#include "ElunaTemplate.h" +#include "ElunaIncludes.h" + +#ifndef CUSTOMMETHODS_H +#define CUSTOMMETHODS_H + +namespace LuaCustom +{ + // Define a custom method that returns the players name + int CustomPlayerMethod(Eluna* E, Player* player) + { + E->Push(player->GetName()); + return 1; + } + + // Create a custom player method registry + ElunaRegister CustomPlayerMethods[] = + { + // Add the custom player method to the registry + { "CustomPlayerMethod", &LuaCustom::CustomPlayerMethod }, + }; + + inline void RegisterCustomMethods([[maybe_unused]] Eluna* E) + { + // Append all the custom Player methods to the Player object + ElunaTemplate::SetMethods(E, CustomPlayerMethods); + }; +}; + +#endif diff --git a/methods/VMangos/CustomMethods.h b/methods/VMangos/CustomMethods.h new file mode 100644 index 0000000000..346bdddb22 --- /dev/null +++ b/methods/VMangos/CustomMethods.h @@ -0,0 +1,27 @@ +/* +* Copyright (C) 2010 - 2024 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// This file is used for custom Lua methods, without needing to edit the existing method header files. +// This can also be used to override default methods without needing to edit existing methods. +// It follows the same structure as any other method header, except you can use RegisterCustomFunction +// to register multiple method tables in a single file. + +#include "ElunaTemplate.h" +#include "ElunaIncludes.h" + +#ifndef CUSTOMMETHODS_H +#define CUSTOMMETHODS_H + +namespace LuaCustom +{ + // See the CustomMethods header file in the TC method directory for an example. + inline void RegisterCustomMethods([[maybe_unused]] Eluna* E) + { + + }; +}; + +#endif