mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Eluna fix reload crash and add more asserts
This commit is contained in:
@@ -33,9 +33,10 @@ public:
|
|||||||
int args = lua_gettop(L);
|
int args = lua_gettop(L);
|
||||||
int expected = l->mfunc(E, L);
|
int expected = l->mfunc(E, L);
|
||||||
args = lua_gettop(L) - args;
|
args = lua_gettop(L) - args;
|
||||||
if (args < 0 || args > expected) // Assert instead?
|
if (args < 0 || args > expected)
|
||||||
{
|
{
|
||||||
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected);
|
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected);
|
||||||
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
for (; args < expected; ++args)
|
for (; args < expected; ++args)
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
@@ -44,8 +45,8 @@ public:
|
|||||||
|
|
||||||
static void SetMethods(Eluna* E, ElunaRegister* methodTable)
|
static void SetMethods(Eluna* E, ElunaRegister* methodTable)
|
||||||
{
|
{
|
||||||
if (!methodTable)
|
ASSERT(E);
|
||||||
return;
|
ASSERT(methodTable);
|
||||||
|
|
||||||
lua_pushglobaltable(E->L);
|
lua_pushglobaltable(E->L);
|
||||||
|
|
||||||
@@ -132,20 +133,33 @@ 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(Eluna* E, const char* name, bool gc = false)
|
static void Register(Eluna* E, const char* name, bool gc = false)
|
||||||
{
|
{
|
||||||
ASSERT(!tname && name);
|
ASSERT(E);
|
||||||
|
ASSERT(name);
|
||||||
|
|
||||||
|
// check that metatable isn't already there
|
||||||
|
luaL_getmetatable(E->L, name);
|
||||||
|
ASSERT(lua_isnoneornil(E->L, -1));
|
||||||
|
|
||||||
|
// check that metatable isn't already there
|
||||||
|
lua_getglobal(E->L, name);
|
||||||
|
ASSERT(lua_isnoneornil(E->L, -1));
|
||||||
|
|
||||||
|
// pop metatable and methodtable values
|
||||||
|
lua_pop(E->L, 2);
|
||||||
|
|
||||||
tname = name;
|
tname = name;
|
||||||
manageMemory = gc;
|
manageMemory = gc;
|
||||||
|
|
||||||
|
// create methodtable for userdata of this type
|
||||||
lua_newtable(E->L);
|
lua_newtable(E->L);
|
||||||
int methods = lua_gettop(E->L);
|
int methods = lua_gettop(E->L);
|
||||||
|
|
||||||
// store method table in globals so that
|
// push methodtable to stack to be accessed and modified by users
|
||||||
// scripts can add functions in Lua
|
|
||||||
lua_pushvalue(E->L, methods);
|
lua_pushvalue(E->L, methods);
|
||||||
lua_setglobal(E->L, tname);
|
lua_setglobal(E->L, tname);
|
||||||
|
|
||||||
luaL_newmetatable(E->L, tname);
|
// create metatable for userdatas of this type
|
||||||
|
ASSERT(luaL_newmetatable(E->L, tname));
|
||||||
int metatable = lua_gettop(E->L);
|
int metatable = lua_gettop(E->L);
|
||||||
|
|
||||||
// tostring
|
// tostring
|
||||||
@@ -231,25 +245,18 @@ public:
|
|||||||
template<typename C>
|
template<typename C>
|
||||||
static void SetMethods(Eluna* E, ElunaRegister<C>* methodTable)
|
static void SetMethods(Eluna* E, ElunaRegister<C>* methodTable)
|
||||||
{
|
{
|
||||||
if (!methodTable)
|
ASSERT(E);
|
||||||
return;
|
ASSERT(tname);
|
||||||
|
ASSERT(methodTable);
|
||||||
|
|
||||||
|
// get metatable
|
||||||
luaL_getmetatable(E->L, tname);
|
luaL_getmetatable(E->L, tname);
|
||||||
if (!lua_istable(E->L, -1))
|
ASSERT(lua_istable(E->L, -1));
|
||||||
{
|
|
||||||
lua_remove(E->L, -1);
|
|
||||||
ELUNA_LOG_ERROR("%s missing metatable", tname);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// get method table
|
||||||
lua_getfield(E->L, -1, "__index");
|
lua_getfield(E->L, -1, "__index");
|
||||||
lua_remove(E->L, -2);
|
lua_remove(E->L, -2);
|
||||||
if (!lua_istable(E->L, -1))
|
ASSERT(lua_istable(E->L, -1));
|
||||||
{
|
|
||||||
lua_remove(E->L, -1);
|
|
||||||
ELUNA_LOG_ERROR("%s missing method table from metatable", tname);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; methodTable && methodTable->name && methodTable->mfunc; ++methodTable)
|
for (; methodTable && methodTable->name && methodTable->mfunc; ++methodTable)
|
||||||
{
|
{
|
||||||
@@ -395,9 +402,10 @@ public:
|
|||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
int expected = l->mfunc(E, L, obj);
|
int expected = l->mfunc(E, L, obj);
|
||||||
int args = lua_gettop(L) - top;
|
int args = lua_gettop(L) - top;
|
||||||
if (args < 0 || args > expected) // Assert instead?
|
if (args < 0 || args > expected)
|
||||||
{
|
{
|
||||||
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected);
|
ELUNA_LOG_ERROR("[Eluna]: %s returned unexpected amount of arguments %i out of %i. Report to devs", l->name, args, expected);
|
||||||
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
if (args == expected)
|
if (args == expected)
|
||||||
return expected;
|
return expected;
|
||||||
|
|||||||
Reference in New Issue
Block a user