25template<
typename T>
const char*
GetTName();
38 static int type(lua_State* L)
49 int methods = lua_gettop(L);
52 int metatable = lua_gettop(L);
56 lua_pushvalue(L, methods);
60 lua_pushvalue(L, methods);
61 lua_setfield(L, metatable,
"__metatable");
63 lua_pushvalue(L, methods);
64 lua_setfield(L, metatable,
"__index");
67 lua_setfield(L, metatable,
"__tostring");
69 lua_pushcfunction(L,
gcT);
70 lua_setfield(L, metatable,
"__gc");
73 lua_setmetatable(L, methods);
76 static int push(lua_State* L, T
const* obj,
bool gc =
false)
85 luaL_error(L,
"%s missing metatable",
GetTName<T>());
86 int idxMt = lua_gettop(L);
87 T
const** ptrHold = (T
const**)lua_newuserdata(L,
sizeof(T**));
88 int ud = lua_gettop(L);
92 lua_pushvalue(L, idxMt);
93 lua_setmetatable(L, -2);
96 lua_getfield(L, LUA_REGISTRYINDEX,
"DO NOT TRASH");
99 luaL_newmetatable(L,
"DO NOT TRASH");
102 lua_getfield(L, LUA_REGISTRYINDEX,
"DO NOT TRASH");
105 lua_pushboolean(L, 1);
106 lua_setfield(L, -2, name);
111 lua_replace(L, idxMt);
112 lua_settop(L, idxMt);
116 static T*
check(lua_State* L,
int narg)
118 T** ptrHold =
static_cast<T**
>(lua_touserdata(L, narg));
126 T* obj =
check(L, 1);
131 return l->
mfunc(L, obj);
134 static int gcT(lua_State* L)
136 T* obj =
check(L, 1);
139 lua_getfield(L, LUA_REGISTRYINDEX,
"DO NOT TRASH");
140 if (lua_istable(L, -1))
144 lua_getfield(L, -1, std::string(name).c_str());
152 T** ptrHold = (T**)lua_touserdata(L, 1);
154 sprintf(buff,
"%p", obj);
155 lua_pushfstring(L,
"%s (%s)",
GetTName<T>(), buff);
159 inline static void tostring(
char* buff,
void const* obj)
161 sprintf(buff,
"%p", obj);
167 const char* key = lua_tostring(L, 2);
168 if (lua_istable(L, - 1))
172 if (lua_isnil(L, -1))
174 lua_getmetatable(L, -2);
175 if (lua_istable(L, -1))
177 lua_getfield(L, -1,
"__index");
178 if (lua_isfunction(L, -1))
182 lua_pcall(L, 2, 1, 0);
184 else if (lua_istable(L, -1))
185 lua_getfield(L, -1, key);
192 else if (lua_istable(L, -1))
211 if (!lua_istable(L, 1))
213 lua_pushstring(L,
"GetObjectType");
216 for (; methodTable->
name; ++methodTable)
218 lua_pushstring(L, methodTable->
name);
219 lua_pushlightuserdata(L, (
void*)methodTable);
230 typedef std::map<EventProcessor*, EventSet>
EventMap;
260 it->second.Update(diff);
279 EventMap::const_iterator it =
LuaEvents.find(events);
282 for (EventSet::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr)
283 (*itr)->to_Abort =
true;
290 it->second.KillAllEvents(
true);
318 if (!events || funcRef <= 0)
335 if (!events || !eventId)
337 EventMap::const_iterator it =
LuaEvents.find(events);
340 for (EventSet::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr)
341 if ((*itr) && (*itr)->funcRef == eventId)
350 if (!events || !eventId)
404 static void report(lua_State*);
411 void Push(lua_State*);
416 void Push(lua_State*,
bool);
417 void Push(lua_State*,
float);
418 void Push(lua_State*,
double);
419 void Push(lua_State*,
const char*);
420 void Push(lua_State*, std::string);
421 template<typename T, typename std::enable_if<std::is_enum<T>::value,
int>::type = 0>
426 template<
typename T>
void Push(lua_State*
L, T
const* ptr)
536 std::vector<int> _vector;
542 std::vector<int> _vector;
548 std::vector<int> _vector;
554 std::vector<int> _vector;
560 std::vector<int> _vector;
576 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
577 luaL_unref(
L, LUA_REGISTRYINDEX, (*it));
583 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
584 luaL_unref(
L, LUA_REGISTRYINDEX, (*it));
590 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
591 luaL_unref(
L, LUA_REGISTRYINDEX, (*it));
597 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
598 luaL_unref(
L, LUA_REGISTRYINDEX, (*it));
604 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
605 luaL_unref(
L, LUA_REGISTRYINDEX, (*it));
632 ElunaEntryMap::iterator itr =
Bindings.find(entryId);
636 return itr->second[eventId];
642 ElunaEntryMap::iterator itr =
Bindings.find(entryId);
657 return object->GetGUID() ==
_GUID;
694 if (!unit->IsAlive())
710#define sEluna Eluna::instance()
static constexpr TypeID TYPEID_PLAYER
static constexpr TypeID TYPEID_OBJECT
static constexpr TypeID TYPEID_CORPSE
static constexpr TypeID TYPEID_UNIT
static constexpr TypeID TYPEID_GAMEOBJECT
void StartEluna(bool restart)
void SetMethods(lua_State *L, ElunaRegister< T > *methodTable)
std::set< std::string > LoadedScripts
WorldObject const * i_obj
bool operator()(WorldObject *u)
WorldObjectInRangeCheck(bool nearest, WorldObject const *obj, float range, TypeID typeId=TYPEID_OBJECT, uint32 entry=0)
WorldObjectInRangeCheck(WorldObjectInRangeCheck const &)
WorldObject const & GetFocusObject() const
int64 CHECK_LONG(lua_State *L, int narg)
void Push(lua_State *, WorldObject const *obj)
Quest * CHECK_QUEST(lua_State *L, int narg)
Corpse * CHECK_CORPSE(lua_State *L, int narg)
ElunaBind * CreatureGossipBindings
void Push(lua_State *L, T const *ptr)
Spell * CHECK_SPELL(lua_State *L, int narg)
void Push(lua_State *L, TempSummon const *summon)
Item * CHECK_ITEM(lua_State *L, int narg)
void BeginCall(int fReference)
std::map< int, std::vector< int > > PlayerEventBindings
ElunaBind * ItemEventBindings
ElunaBind * CreatureEventBindings
std::map< int, std::vector< int > > GuildEventBindings
Object * CHECK_OBJECT(lua_State *L, int narg)
void Push(lua_State *L, Pet const *pet)
std::map< int, std::vector< int > > VehicleEventBindings
void Register(uint8 reg, uint32 id, uint32 evt, int func)
std::map< int, std::vector< int > > ServerEventBindings
WorldObject * CHECK_WORLDOBJECT(lua_State *L, int narg)
ElunaBind * playerGossipBindings
std::unordered_map< uint32, ElunaBindingMap > ElunaEntryMap
static void report(lua_State *)
std::map< int, std::vector< int > > GroupEventBindings
Vehicle * CHECK_VEHICLE(lua_State *L, int narg)
std::map< int, int > ElunaBindingMap
Creature * CHECK_CREATURE(lua_State *L, int narg)
static Eluna * instance()
void Push(lua_State *L, Unit const *unit)
void LoadDirectory(const char *directory, LoadedScripts *scr)
ElunaBind * ItemGossipBindings
uint64 CHECK_ULONG(lua_State *L, int narg)
GameObject * CHECK_GAMEOBJECT(lua_State *L, int narg)
void Push(lua_State *L, T value)
Player * CHECK_PLAYER(lua_State *L, int narg)
ElunaBind * GameObjectEventBindings
WorldPacket * CHECK_PACKET(lua_State *L, int narg)
bool ExecuteCall(uint8 params, uint8 res)
void Push(lua_State *L, Object const *obj)
ElunaBind * GameObjectGossipBindings
Unit * CHECK_UNIT(lua_State *L, int narg)
static int tostringT(lua_State *L)
static int thunk(lua_State *L)
static T * check(lua_State *L, int narg)
static int index(lua_State *L)
static int type(lua_State *L)
static void tostring(char *buff, void const *obj)
static int gcT(lua_State *L)
static int push(lua_State *L, T const *obj, bool gc=false)
static void Register(lua_State *L)
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
uint64 CalculateTime(uint64 t_offset) const
static void StartTaxi(Player *player, uint32 pathid)
static uint32 AddPath(std::list< TaxiPathNodeEntry > nodes, uint32 mountA, uint32 mountH, uint32 price=0, uint32 pathId=0)
GameObject * ToGameObject()
ElunaBindingMap * GetBindMap(uint32 entryId)
void Insert(uint32 entryId, uint32 eventId, int funcRef)
int GetBind(uint32 entryId, uint32 eventId)
bool operator()(WorldObject const *pLeft, WorldObject const *pRight) const
WorldObject const * m_refObj
ObjectDistanceOrderPred(WorldObject const *pRefObj, bool ascending=true)
ObjectGUIDCheck(uint64 GUID)
bool operator()(WorldObject *object)
int(* mfunc)(lua_State *, T *)
LuaEvent(EventProcessor *_events, int _funcRef, uint32 _delay, uint32 _calls, Object *_obj)
bool Execute(uint64 time, uint32 diff)
EventProcessor GlobalEvents
void RemoveEvents(uint64 guid)
std::unordered_map< uint64, EventProcessor > ProcessorMap
bool RemoveEvent(uint64 guid, int eventId)
void RemoveEvents(EventProcessor *events)
std::map< EventProcessor *, EventSet > EventMap
void KillAllEvents(EventProcessor *events)
void RemoveEvent(int eventId)
bool RemoveEvent(EventProcessor *events, int eventId)
std::set< LuaEvent * > EventSet
int AddEvent(uint64 guid, int funcRef, uint32 delay, uint32 calls, Object *obj=NULL)
LuaEvent * GetEvent(EventProcessor *events, int eventId)
int AddEvent(EventProcessor *events, int funcRef, uint32 delay, uint32 calls, Object *obj=NULL)