Skip to content

Commit

Permalink
Move method registry and implement Custom Method template files
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Nov 11, 2024
1 parent 5e0a1c5 commit adf3f95
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
27 changes: 27 additions & 0 deletions methods/CMangos/CustomMethods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
* 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 RegisterCustomFunctions(Eluna* E)
{

};
};

#endif
27 changes: 27 additions & 0 deletions methods/Mangos/CustomMethods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
* 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 RegisterCustomFunctions(Eluna* E)
{

};
};

#endif
6 changes: 6 additions & 0 deletions LuaMethods.cpp → methods/Methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "VehicleMethods.h"
#include "BattleGroundMethods.h"

// Custom methods
#include "CustomMethods.h"

void RegisterMethods(Eluna* E)
{
ElunaTemplate<>::SetMethods(E, LuaGlobalFunctions::GlobalMethods);
Expand Down Expand Up @@ -112,5 +115,8 @@ void RegisterMethods(Eluna* E)

ElunaTemplate<ObjectGuid>::Register(E, "ObjectGuid");

// Register custom functions
LuaCustom::RegisterCustomFunctions(E);

LuaVal::Register(E->L);
}
41 changes: 41 additions & 0 deletions methods/TrinityCore/CustomMethods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
* 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<Player> CustomPlayerMethods[] =
{
// Add the custom player method to the registry
{ "CustomPlayerMethod", &LuaCustom::CustomPlayerMethod },
};

inline void RegisterCustomFunctions(Eluna* E)
{
// Append all the custom Player methods to the Player object
ElunaTemplate<Player>::SetMethods(E, CustomPlayerMethods);
};
};

#endif
27 changes: 27 additions & 0 deletions methods/VMangos/CustomMethods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
* 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 RegisterCustomFunctions(Eluna* E)
{

};
};

#endif

0 comments on commit adf3f95

Please sign in to comment.