Eluna Closes:

#70, #69, #83, http://emudevs.com/showthread.php/3438-Custom-Items-and-On-Item-Use-Events
Fixes Object::~Object crash log from #71
This commit is contained in:
Rochet2
2014-07-01 00:35:06 +03:00
parent 8fe509c838
commit d09b5b04ba
6 changed files with 70 additions and 17 deletions

View File

@@ -859,28 +859,35 @@ public:
luaL_newmetatable(L, tname);
int metatable = lua_gettop(L);
// tostring
lua_pushcfunction(L, tostringT);
lua_setfield(L, metatable, "__tostring");
// garbage collecting
if (manageMemory)
{
lua_pushcfunction(L, gcT);
lua_setfield(L, metatable, "__gc");
}
// hide metatable
lua_pushvalue(L, methods);
lua_setfield(L, metatable, "__metatable");
// required to access methods
// make methods accessible through metatable
lua_pushvalue(L, methods);
lua_setfield(L, metatable, "__index");
// metamethods
lua_pushcfunction(L, tostringT);
lua_setfield(L, metatable, "__tostring");
lua_pushcfunction(L, gcT);
lua_setfield(L, metatable, "__gc");
// make new indexes saved to methods
lua_pushvalue(L, methods);
lua_setfield(L, metatable, "__newindex");
// special method to get the object type
lua_pushcfunction(L, typeT);
lua_setfield(L, methods, "GetObjectType");
lua_setfield(L, metatable, "GetObjectType");
lua_setmetatable(L, methods);
lua_remove(L, methods);
// pop methods and metatable
lua_pop(L, 2);
}
template<typename C>
@@ -897,7 +904,7 @@ public:
return;
}
lua_getfield(L, -1, "__metatable");
lua_getfield(L, -1, "__index");
lua_remove(L, -2);
if (!lua_istable(L, -1))
{