Change Eluna to a global variable

Remove Eluna* from being passed. You can now get it through Eluna::GetEluna(L)
Change function call cleanup to lua_settop instead of manual loop
Explicitly delete the copy constructor and copy assignment operators
This commit is contained in:
Rochet2
2017-03-19 15:48:48 +02:00
parent 8d3433f4b5
commit b7c379a42c
23 changed files with 990 additions and 976 deletions

View File

@@ -112,6 +112,7 @@ struct LuaScript
};
#define ELUNA_OBJECT_STORE "Eluna Object Store"
#define ELUNA_STATE_PTR "Eluna State Ptr"
#define LOCK_ELUNA Eluna::Guard __guard(Eluna::GetLock())
#ifndef TRINITY
@@ -154,8 +155,8 @@ private:
~Eluna();
// Prevent copy
Eluna(Eluna const&);
Eluna& operator=(const Eluna&);
Eluna(Eluna const&) = delete;
Eluna& operator=(const Eluna&) = delete;
void OpenLua();
void CloseLua();
@@ -247,6 +248,17 @@ public:
static void ReloadEluna() { LOCK_ELUNA; reload = true; }
static LockType& GetLock() { return lock; };
static bool IsInitialized() { return initialized; }
// Never returns nullptr
static Eluna* GetEluna(lua_State* L)
{
lua_pushstring(L, ELUNA_STATE_PTR);
lua_rawget(L, LUA_REGISTRYINDEX);
ASSERT(lua_islightuserdata(L, -1));
Eluna* E = static_cast<Eluna*>(lua_touserdata(L, -1));
lua_pop(L, 1);
ASSERT(E);
return E;
}
// Static pushes, can be used by anything, including methods.
static void Push(lua_State* luastate); // nil