diff options
author | aunsane <aunsane@gmail.com> | 2018-03-21 01:28:14 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-03-21 01:28:26 +0300 |
commit | b987b7a8e5a78ff3cd63da062917b1c5fce91cc2 (patch) | |
tree | a34569e27dc149310ff4f95e6a93ad387de359e5 /plugins/MirLua/src/mlua_environment.cpp | |
parent | 165d7791631a9c9ed0998c90b696116593ebfd70 (diff) |
MurLua: various fixes
- fixed script reloading
- fixed string interpolation
- hook and service refs moved to Enviroment
- removed RegisterProtocol from m_protocols
- code cleanup
- version bump
Diffstat (limited to 'plugins/MirLua/src/mlua_environment.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_environment.cpp | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/plugins/MirLua/src/mlua_environment.cpp b/plugins/MirLua/src/mlua_environment.cpp index 9c28645274..4a82e63231 100644 --- a/plugins/MirLua/src/mlua_environment.cpp +++ b/plugins/MirLua/src/mlua_environment.cpp @@ -6,18 +6,24 @@ CMLuaEnvironment::CMLuaEnvironment(lua_State *L) : L(L) { MUUID muidLast = MIID_LAST; - id = GetPluginLangId(muidLast, 0); + m_id = GetPluginLangId(muidLast, 0); } CMLuaEnvironment::~CMLuaEnvironment() { - KillModuleIcons(id); - KillModuleSounds(id); - KillModuleMenus(id); - KillModuleHotkeys(id); + 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) @@ -42,7 +48,31 @@ int CMLuaEnvironment::GetEnvironmentId(lua_State *L) int CMLuaEnvironment::GetId() const { - return id; + 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() |