Permalink
Browse files

Move objects from global table to internal registery

  • Loading branch information...
1 parent 849d26e commit d162ae41059d9b251148193849724865cfd2d3ef @Rochet2 Rochet2 committed Feb 24, 2016
Showing with 11 additions and 7 deletions.
  1. +8 −5 ElunaTemplate.h
  2. +3 −2 LuaEngine.cpp
View
@@ -148,7 +148,7 @@ class ElunaTemplate
manageMemory = gc;
// create metatable for userdata of this type
- lua_newtable(E->L);
+ luaL_newmetatable(E->L, tname);
int metatable = lua_gettop(E->L);
// push methodtable to stack to be accessed and modified by users
@@ -239,7 +239,8 @@ class ElunaTemplate
ASSERT(methodTable);
// get metatable
- lua_getglobal(E->L, tname);
+ lua_pushstring(E->L, tname);
+ lua_rawget(E->L, LUA_REGISTRYINDEX);
ASSERT(lua_istable(E->L, -1));
for (; methodTable && methodTable->name && methodTable->mfunc; ++methodTable)
@@ -264,7 +265,8 @@ class ElunaTemplate
void* obj_voidptr = static_cast<void*>(const_cast<T*>(obj));
- lua_getglobal(L, ELUNA_OBJECT_STORE);
+ lua_pushstring(L, ELUNA_OBJECT_STORE);
+ lua_rawget(L, LUA_REGISTRYINDEX);
ASSERT(lua_istable(L, -1));
lua_pushlightuserdata(L, obj_voidptr);
lua_rawget(L, -2);
@@ -292,7 +294,8 @@ class ElunaTemplate
*ptrHold = new ElunaObject(const_cast<T*>(obj), manageMemory);
// Set metatable for it
- lua_getglobal(L, tname);
+ lua_pushstring(L, tname);
+ lua_rawget(L, LUA_REGISTRYINDEX);
if (!lua_istable(L, -1))
{
ELUNA_LOG_ERROR("%s missing metatable", tname);
@@ -384,7 +387,7 @@ class ElunaTemplate
static int ToString(lua_State* L)
{
T* obj = Eluna::CHECKOBJ<T>(L, 1, true); // get self
- lua_pushfstring(L, "%s: (%p)", tname, obj);
+ lua_pushfstring(L, "%s: %p", tname, obj);
return 1;
}
View
@@ -242,7 +242,7 @@ void Eluna::OpenLua()
lua_pushstring(L, "v");
lua_setfield(L, -2, "__mode");
lua_setmetatable(L, -2);
- lua_setglobal(L, ELUNA_OBJECT_STORE);
+ lua_setfield(L, LUA_REGISTRYINDEX, ELUNA_OBJECT_STORE);
// Set lua require folder paths (scripts folder structure)
lua_getglobal(L, "package");
@@ -534,7 +534,8 @@ void Eluna::RunScripts()
void Eluna::InvalidateObjects()
{
- lua_getglobal(L, ELUNA_OBJECT_STORE);
+ lua_pushstring(L, ELUNA_OBJECT_STORE);
+ lua_rawget(L, LUA_REGISTRYINDEX);
ASSERT(lua_istable(L, -1));
lua_pushnil(L);

0 comments on commit d162ae4

Please sign in to comment.