diff options
author | aunsane <aunsane@gmail.com> | 2018-05-20 21:10:10 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-05-20 21:34:31 +0300 |
commit | a955d18f62f335f84e0926f351eb85d78224cba6 (patch) | |
tree | 7bd4d30040ec32bba5949dd2245cb68617fb4192 /plugins/MirLua/src/mlua_environment.cpp | |
parent | 46363eef857b69761f1d6d28da5a53a954f76900 (diff) |
MirLua: project reordering
Diffstat (limited to 'plugins/MirLua/src/mlua_environment.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_environment.cpp | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/plugins/MirLua/src/mlua_environment.cpp b/plugins/MirLua/src/mlua_environment.cpp deleted file mode 100644 index 4a82e63231..0000000000 --- a/plugins/MirLua/src/mlua_environment.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "stdafx.h" - -#define MT_ENVIRONMENT "ENVIRONMENT" - -CMLuaEnvironment::CMLuaEnvironment(lua_State *L) - : L(L) -{ - MUUID muidLast = MIID_LAST; - m_id = GetPluginLangId(muidLast, 0); -} - -CMLuaEnvironment::~CMLuaEnvironment() -{ - KillModuleIcons(m_id); - KillModuleSounds(m_id); - KillModuleMenus(m_id); - KillModuleHotkeys(m_id); - - KillObjectEventHooks(this); - KillObjectServices(this); - - for (auto &it : m_hookRefs) - luaL_unref(L, LUA_REGISTRYINDEX, it.second); - - for (auto &it : m_serviceRefs) - luaL_unref(L, LUA_REGISTRYINDEX, it.second); -} - -CMLuaEnvironment* CMLuaEnvironment::GetEnvironment(lua_State *L) -{ - if (!luaM_getenv(L)) - return nullptr; - - lua_rawgeti(L, -1, NULL); - CMLuaEnvironment *env = (CMLuaEnvironment*)lua_touserdata(L, -1); - lua_pop(L, 3); - - return env; -} - -int CMLuaEnvironment::GetEnvironmentId(lua_State *L) -{ - CMLuaEnvironment *script = GetEnvironment(L); - return script != nullptr - ? script->GetId() - : hMLuaLangpack; -} - -int CMLuaEnvironment::GetId() const -{ - return m_id; -} - -void CMLuaEnvironment::AddHookRef(HANDLE h, int ref) -{ - m_hookRefs[h] = ref; -} - -void CMLuaEnvironment::ReleaseHookRef(HANDLE h) -{ - auto it = m_hookRefs.find(h); - if (it != m_hookRefs.end()) - luaL_unref(L, LUA_REGISTRYINDEX, it->second); -} - -void CMLuaEnvironment::AddServiceRef(HANDLE h, int ref) -{ - m_serviceRefs[h] = ref; -} - -void CMLuaEnvironment::ReleaseServiceRef(HANDLE h) -{ - auto it = m_serviceRefs.find(h); - if (it != m_serviceRefs.end()) - luaL_unref(L, LUA_REGISTRYINDEX, it->second); -} - -void CMLuaEnvironment::CreateEnvironmentTable() -{ - lua_createtable(L, 1, 1); - lua_pushlightuserdata(L, this); - lua_rawseti(L, -2, NULL); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "_G"); - lua_createtable(L, 0, 2); - lua_pushliteral(L, MT_ENVIRONMENT); - lua_setfield(L, -2, "__metatable"); - lua_getglobal(L, "_G"); - lua_setfield(L, -2, "__index"); - lua_setmetatable(L, -2); -} - -bool CMLuaEnvironment::Load() -{ - luaL_checktype(L, -1, LUA_TFUNCTION); - - CreateEnvironmentTable(); - lua_setupvalue(L, -2, 1); - - return lua_pcall(L, 0, 1, 0) == LUA_OK; -} |