forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLuaFunctions.cpp
227 lines (193 loc) · 10.8 KB
/
LuaFunctions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* Copyright (C) 2010 - 2023 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
*/
extern "C"
{
#include "lua.h"
};
// 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<Aura> 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<BattleGround> GetWeakPtrFor(BattleGround const* obj) { return { obj->GetWeakPtr(), obj->GetBgMap() }; }
ElunaConstrainedObjectRef<Group> GetWeakPtrFor(Group const* obj) { return { obj->GetWeakPtr(), nullptr }; }
ElunaConstrainedObjectRef<Guild> GetWeakPtrFor(Guild const* obj) { return { obj->GetWeakPtr(), nullptr }; }
ElunaConstrainedObjectRef<Map> GetWeakPtrFor(Map const* obj) { return { obj->GetWeakPtr(), obj }; }
ElunaConstrainedObjectRef<Object> GetWeakPtrForObjectImpl(Object const* obj)
{
if (obj->isType(TYPEMASK_WORLDOBJECT))
return { obj->GetWeakPtr(), static_cast<WorldObject const*>(obj)->GetMap() };
if (obj->GetTypeId() == TYPEID_ITEM)
if (Player const* player = static_cast<Item const*>(obj)->GetOwner())
return { obj->GetWeakPtr(), player->GetMap() };
// possibly dangerous item
return { obj->GetWeakPtr(), nullptr };
}
ElunaConstrainedObjectRef<Quest> GetWeakPtrFor(Quest const* obj) { return { obj->GetWeakPtr(), nullptr }; }
ElunaConstrainedObjectRef<Spell> GetWeakPtrFor(Spell const* obj) { return { obj->GetWeakPtr(), obj->GetCaster()->GetMap() }; }
#if ELUNA_EXPANSION >= EXP_WOTLK
ElunaConstrainedObjectRef<Vehicle> 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 by Mud from http://stackoverflow.com/questions/4484437/lua-integer-type/4485511#4485511
template<> int ElunaTemplate<unsigned long long>::Add(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) + E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Substract(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) - E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Multiply(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) * E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Divide(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) / E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Mod(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) % E->CHECKVAL<unsigned long long>(2)); return 1; }
// template<> int ElunaTemplate<unsigned long long>::UnaryMinus(lua_State* L) { Eluna::GetEluna(L)->Push(-E->CHECKVAL<unsigned long long>(L, 1)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Equal(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) == E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Less(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) < E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::LessOrEqual(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<unsigned long long>(1) <= E->CHECKVAL<unsigned long long>(2)); return 1; }
template<> int ElunaTemplate<unsigned long long>::Pow(lua_State* L)
{
Eluna* E = Eluna::GetEluna(L);
E->Push(static_cast<unsigned long long>(powl(static_cast<long double>(E->CHECKVAL<unsigned long long>(1)), static_cast<long double>(E->CHECKVAL<unsigned long long>(2)))));
return 1;
}
template<> int ElunaTemplate<unsigned long long>::ToString(lua_State* L)
{
Eluna* E = Eluna::GetEluna(L);
unsigned long long l = E->CHECKVAL<unsigned long long>(1);
std::ostringstream ss;
ss << l;
E->Push(ss.str());
return 1;
}
template<> int ElunaTemplate<long long>::Add(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) + E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::Substract(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) - E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::Multiply(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) * E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::Divide(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) / E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::Mod(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) % E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::UnaryMinus(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(-E->CHECKVAL<long long>(1)); return 1; }
template<> int ElunaTemplate<long long>::Equal(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) == E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::Less(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) < E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::LessOrEqual(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<long long>(1) <= E->CHECKVAL<long long>(2)); return 1; }
template<> int ElunaTemplate<long long>::Pow(lua_State* L)
{
Eluna* E = Eluna::GetEluna(L);
E->Push(static_cast<long long>(powl(static_cast<long double>(E->CHECKVAL<long long>(1)), static_cast<long double>(E->CHECKVAL<long long>(2)))));
return 1;
}
template<> int ElunaTemplate<long long>::ToString(lua_State* L)
{
Eluna* E = Eluna::GetEluna(L);
long long l = E->CHECKVAL<long long>(1);
std::ostringstream ss;
ss << l;
E->Push(ss.str());
return 1;
}
template<> int ElunaTemplate<ObjectGuid>::Equal(lua_State* L) { Eluna* E = Eluna::GetEluna(L); E->Push(E->CHECKVAL<ObjectGuid>(1) == E->CHECKVAL<ObjectGuid>(2)); return 1; }
template<> int ElunaTemplate<ObjectGuid>::ToString(lua_State* L)
{
Eluna* E = Eluna::GetEluna(L);
#if defined ELUNA_TRINITY
E->Push(E->CHECKVAL<ObjectGuid>(1).ToString());
#else
E->Push(E->CHECKVAL<ObjectGuid>(1).GetString());
#endif
return 1;
}
void RegisterFunctions(Eluna* E)
{
ElunaTemplate<>::SetMethods(E, LuaGlobalFunctions::GlobalMethods);
ElunaTemplate<Object>::Register(E, "Object");
ElunaTemplate<Object>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<WorldObject>::Register(E, "WorldObject");
ElunaTemplate<WorldObject>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<WorldObject>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
ElunaTemplate<Unit>::Register(E, "Unit");
ElunaTemplate<Unit>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Unit>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
ElunaTemplate<Unit>::SetMethods(E, LuaUnit::UnitMethods);
ElunaTemplate<Player>::Register(E, "Player");
ElunaTemplate<Player>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Player>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
ElunaTemplate<Player>::SetMethods(E, LuaUnit::UnitMethods);
ElunaTemplate<Player>::SetMethods(E, LuaPlayer::PlayerMethods);
ElunaTemplate<Creature>::Register(E, "Creature");
ElunaTemplate<Creature>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Creature>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
ElunaTemplate<Creature>::SetMethods(E, LuaUnit::UnitMethods);
ElunaTemplate<Creature>::SetMethods(E, LuaCreature::CreatureMethods);
ElunaTemplate<GameObject>::Register(E, "GameObject");
ElunaTemplate<GameObject>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<GameObject>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
ElunaTemplate<GameObject>::SetMethods(E, LuaGameObject::GameObjectMethods);
ElunaTemplate<Corpse>::Register(E, "Corpse");
ElunaTemplate<Corpse>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Corpse>::SetMethods(E, LuaWorldObject::WorldObjectMethods);
ElunaTemplate<Corpse>::SetMethods(E, LuaCorpse::CorpseMethods);
ElunaTemplate<Item>::Register(E, "Item");
ElunaTemplate<Item>::SetMethods(E, LuaObject::ObjectMethods);
ElunaTemplate<Item>::SetMethods(E, LuaItem::ItemMethods);
#if ELUNA_EXPANSION >= EXP_WOTLK
ElunaTemplate<Vehicle>::Register(E, "Vehicle");
ElunaTemplate<Vehicle>::SetMethods(E, LuaVehicle::VehicleMethods);
#endif
ElunaTemplate<Group>::Register(E, "Group");
ElunaTemplate<Group>::SetMethods(E, LuaGroup::GroupMethods);
ElunaTemplate<Guild>::Register(E, "Guild");
ElunaTemplate<Guild>::SetMethods(E, LuaGuild::GuildMethods);
ElunaTemplate<Aura>::Register(E, "Aura");
ElunaTemplate<Aura>::SetMethods(E, LuaAura::AuraMethods);
ElunaTemplate<Spell>::Register(E, "Spell");
ElunaTemplate<Spell>::SetMethods(E, LuaSpell::SpellMethods);
ElunaTemplate<Quest>::Register(E, "Quest");
ElunaTemplate<Quest>::SetMethods(E, LuaQuest::QuestMethods);
ElunaTemplate<Map>::Register(E, "Map");
ElunaTemplate<Map>::SetMethods(E, LuaMap::MapMethods);
ElunaTemplate<BattleGround>::Register(E, "BattleGround");
ElunaTemplate<BattleGround>::SetMethods(E, LuaBattleGround::BattleGroundMethods);
ElunaTemplate<WorldPacket>::Register(E, "WorldPacket");
ElunaTemplate<WorldPacket>::SetMethods(E, LuaPacket::PacketMethods);
ElunaTemplate<ElunaQuery>::Register(E, "ElunaQuery");
ElunaTemplate<ElunaQuery>::SetMethods(E, LuaQuery::QueryMethods);
ElunaTemplate<long long>::Register(E, "long long");
ElunaTemplate<unsigned long long>::Register(E, "unsigned long long");
ElunaTemplate<ObjectGuid>::Register(E, "ObjectGuid");
LuaVal::Register(E->L);
}