Eluna add asserts for typename

This commit is contained in:
Rochet2
2014-09-08 13:27:16 +03:00
parent e956e00a03
commit 10c81df2cd
2 changed files with 20 additions and 5 deletions

View File

@@ -27,11 +27,13 @@ template<typename T>
class ElunaTemplate class ElunaTemplate
{ {
public: public:
static const char* tname; static const char* tname = NULL;
static bool manageMemory; static bool manageMemory = false;
static int typeT(lua_State* L) static int typeT(lua_State* L)
{ {
ASSERT(tname);
lua_pushstring(L, tname); lua_pushstring(L, tname);
return 1; return 1;
} }
@@ -42,6 +44,8 @@ public:
// that will only be needed on lua side and will not be managed by TC/mangos/<core> // that will only be needed on lua side and will not be managed by TC/mangos/<core>
static void Register(lua_State* L, const char* name, bool gc = false) static void Register(lua_State* L, const char* name, bool gc = false)
{ {
ASSERT(!tname);
tname = name; tname = name;
manageMemory = gc; manageMemory = gc;
@@ -86,6 +90,8 @@ public:
template<typename C> template<typename C>
static void SetMethods(lua_State* L, ElunaRegister<C>* methodTable) static void SetMethods(lua_State* L, ElunaRegister<C>* methodTable)
{ {
ASSERT(tname);
if (!methodTable) if (!methodTable)
return; return;
@@ -120,6 +126,8 @@ public:
// Remember special case ElunaTemplate<Vehicle>::gcT // Remember special case ElunaTemplate<Vehicle>::gcT
static int gcT(lua_State* L) static int gcT(lua_State* L)
{ {
ASSERT(tname);
if (!manageMemory) if (!manageMemory)
return 0; return 0;
@@ -132,6 +140,8 @@ public:
static int push(lua_State* L, T const* obj) static int push(lua_State* L, T const* obj)
{ {
ASSERT(tname);
if (!obj) if (!obj)
{ {
lua_pushnil(L); lua_pushnil(L);
@@ -186,6 +196,8 @@ public:
static T* check(lua_State* L, int narg, bool error = true) static T* check(lua_State* L, int narg, bool error = true)
{ {
ASSERT(tname);
T** ptrHold = static_cast<T**>(lua_touserdata(L, narg)); T** ptrHold = static_cast<T**>(lua_touserdata(L, narg));
if (!ptrHold) if (!ptrHold)
{ {
@@ -227,6 +239,8 @@ public:
static int thunk(lua_State* L) static int thunk(lua_State* L)
{ {
ASSERT(tname);
T* obj = Eluna::CHECKOBJ<T>(L, 1); // get self T* obj = Eluna::CHECKOBJ<T>(L, 1); // get self
if (!obj) if (!obj)
return 0; return 0;
@@ -245,6 +259,8 @@ public:
static int tostringT(lua_State* L) static int tostringT(lua_State* L)
{ {
ASSERT(tname);
T* obj = Eluna::CHECKOBJ<T>(L, 1); // get self T* obj = Eluna::CHECKOBJ<T>(L, 1); // get self
if (obj) if (obj)
lua_pushfstring(L, "%s: (%p)", tname, obj); lua_pushfstring(L, "%s: (%p)", tname, obj);

View File

@@ -152,9 +152,9 @@ namespace LuaGlobalFunctions
if (Player* player = it->second->GetPlayer()) if (Player* player = it->second->GetPlayer())
{ {
#ifndef TRINITY #ifndef TRINITY
if (player->GetSession() && ((team >= TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->isGameMaster()))) if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->isGameMaster()))
#else #else
if (player->GetSession() && ((team >= TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->IsGameMaster()))) if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->IsGameMaster()))
#endif #endif
{ {
++i; ++i;
@@ -1262,7 +1262,6 @@ namespace LuaGlobalFunctions
item->SaveToDB(); item->SaveToDB();
#else #else
item->SaveToDB(trans); item->SaveToDB(trans);
SQLTransaction trans = CharacterDatabase.BeginTransaction();
#endif #endif
draft.AddItem(item); draft.AddItem(item);
++addedItems; ++addedItems;