Skip to content

Commit adf3f95

Browse files
committed
Move method registry and implement Custom Method template files
1 parent 5e0a1c5 commit adf3f95

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

methods/CMangos/CustomMethods.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
3+
* This program is free software licensed under GPL version 3
4+
* Please see the included DOCS/LICENSE.md for more information
5+
*/
6+
7+
// This file is used for custom Lua methods, without needing to edit the existing method header files.
8+
// This can also be used to override default methods without needing to edit existing methods.
9+
// It follows the same structure as any other method header, except you can use RegisterCustomFunction
10+
// to register multiple method tables in a single file.
11+
12+
#include "ElunaTemplate.h"
13+
#include "ElunaIncludes.h"
14+
15+
#ifndef CUSTOMMETHODS_H
16+
#define CUSTOMMETHODS_H
17+
18+
namespace LuaCustom
19+
{
20+
// See the CustomMethods header file in the TC method directory for an example.
21+
inline void RegisterCustomFunctions(Eluna* E)
22+
{
23+
24+
};
25+
};
26+
27+
#endif

methods/Mangos/CustomMethods.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
3+
* This program is free software licensed under GPL version 3
4+
* Please see the included DOCS/LICENSE.md for more information
5+
*/
6+
7+
// This file is used for custom Lua methods, without needing to edit the existing method header files.
8+
// This can also be used to override default methods without needing to edit existing methods.
9+
// It follows the same structure as any other method header, except you can use RegisterCustomFunction
10+
// to register multiple method tables in a single file.
11+
12+
#include "ElunaTemplate.h"
13+
#include "ElunaIncludes.h"
14+
15+
#ifndef CUSTOMMETHODS_H
16+
#define CUSTOMMETHODS_H
17+
18+
namespace LuaCustom
19+
{
20+
// See the CustomMethods header file in the TC method directory for an example.
21+
inline void RegisterCustomFunctions(Eluna* E)
22+
{
23+
24+
};
25+
};
26+
27+
#endif

LuaMethods.cpp renamed to methods/Methods.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include "VehicleMethods.h"
3333
#include "BattleGroundMethods.h"
3434

35+
// Custom methods
36+
#include "CustomMethods.h"
37+
3538
void RegisterMethods(Eluna* E)
3639
{
3740
ElunaTemplate<>::SetMethods(E, LuaGlobalFunctions::GlobalMethods);
@@ -112,5 +115,8 @@ void RegisterMethods(Eluna* E)
112115

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

118+
// Register custom functions
119+
LuaCustom::RegisterCustomFunctions(E);
120+
115121
LuaVal::Register(E->L);
116122
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
3+
* This program is free software licensed under GPL version 3
4+
* Please see the included DOCS/LICENSE.md for more information
5+
*/
6+
7+
// This file is used for custom Lua methods, without needing to edit the existing method header files.
8+
// This can also be used to override default methods without needing to edit existing methods.
9+
// It follows the same structure as any other method header, except you can use RegisterCustomFunction
10+
// to register multiple method tables in a single file.
11+
12+
#include "ElunaTemplate.h"
13+
#include "ElunaIncludes.h"
14+
15+
#ifndef CUSTOMMETHODS_H
16+
#define CUSTOMMETHODS_H
17+
18+
namespace LuaCustom
19+
{
20+
// Define a custom method that returns the players name
21+
int CustomPlayerMethod(Eluna* E, Player* player)
22+
{
23+
E->Push(player->GetName());
24+
return 1;
25+
}
26+
27+
// Create a custom player method registry
28+
ElunaRegister<Player> CustomPlayerMethods[] =
29+
{
30+
// Add the custom player method to the registry
31+
{ "CustomPlayerMethod", &LuaCustom::CustomPlayerMethod },
32+
};
33+
34+
inline void RegisterCustomFunctions(Eluna* E)
35+
{
36+
// Append all the custom Player methods to the Player object
37+
ElunaTemplate<Player>::SetMethods(E, CustomPlayerMethods);
38+
};
39+
};
40+
41+
#endif

methods/VMangos/CustomMethods.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
3+
* This program is free software licensed under GPL version 3
4+
* Please see the included DOCS/LICENSE.md for more information
5+
*/
6+
7+
// This file is used for custom Lua methods, without needing to edit the existing method header files.
8+
// This can also be used to override default methods without needing to edit existing methods.
9+
// It follows the same structure as any other method header, except you can use RegisterCustomFunction
10+
// to register multiple method tables in a single file.
11+
12+
#include "ElunaTemplate.h"
13+
#include "ElunaIncludes.h"
14+
15+
#ifndef CUSTOMMETHODS_H
16+
#define CUSTOMMETHODS_H
17+
18+
namespace LuaCustom
19+
{
20+
// See the CustomMethods header file in the TC method directory for an example.
21+
inline void RegisterCustomFunctions(Eluna* E)
22+
{
23+
24+
};
25+
};
26+
27+
#endif

0 commit comments

Comments
 (0)