diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-28 20:05:11 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-28 20:05:11 +0000 |
commit | 23af22967ac679d10ea565b69e6374443f01324e (patch) | |
tree | 34092cc4200cba7cc5014927d42f08bcd780db83 /plugins/MirLua | |
parent | 9eea36312cc4a3a215fe147c215d7afd198ab054 (diff) |
MirLua: added removing hooks/services on reloading
git-svn-id: http://svn.miranda-ng.org/main/trunk@14433 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua')
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 103 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 9 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.h | 3 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_console.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/version.h | 2 |
5 files changed, 111 insertions, 8 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index ed30486aad..90dffe5f7c 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -1,5 +1,69 @@ #include "stdafx.h"
+static LIST<void> Hooks(1, PtrKeySortT);
+static LIST<void> Events(1, PtrKeySortT);
+static LIST<void> Services(1, PtrKeySortT);
+
+struct HandleRefParam
+{
+ HANDLE h;
+ int ref;
+ lua_State *L;
+ HandleRefParam(HANDLE h) : L(NULL), h(h), ref(0) { }
+ HandleRefParam(lua_State *L, HANDLE h, int ref = 0) : L(L), h(h), ref(ref) { }
+};
+static LIST<void> HookRefs(1, HandleKeySortT);
+static LIST<void> ServiceRefs(1, HandleKeySortT);
+
+void CMLua::KillModuleEventHooks()
+{
+ while (Hooks.getCount())
+ {
+ HANDLE hHook = Hooks[0];
+ Hooks.remove(0);
+ UnhookEvent(hHook);
+ }
+
+ while (Events.getCount())
+ {
+ HANDLE hEvent = Events[0];
+ Events.remove(hEvent);
+ DestroyHookableEvent(hEvent);
+ }
+
+ while (HookRefs.getCount())
+ {
+ HandleRefParam *param = (HandleRefParam*)HookRefs[0];
+ if (param != NULL)
+ {
+ luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
+ HookRefs.remove(0);
+ delete param;
+ }
+ }
+}
+
+void CMLua::KillModuleServices()
+{
+ while (Services.getCount())
+ {
+ HANDLE hService = Services[0];
+ Services.remove(0);
+ DestroyServiceFunction(hService);
+ }
+
+ while (ServiceRefs.getCount())
+ {
+ HandleRefParam *param = (HandleRefParam*)ServiceRefs[0];
+ if (param != NULL)
+ {
+ luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
+ ServiceRefs.remove(0);
+ delete param;
+ }
+ }
+}
+
static int lua_CreateHookableEvent(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
@@ -7,6 +71,8 @@ static int lua_CreateHookableEvent(lua_State *L) HANDLE res = ::CreateHookableEvent(name);
lua_pushlightuserdata(L, res);
+ Events.insert(res);
+
return 1;
}
@@ -14,6 +80,8 @@ static int lua_DestroyHookableEvent(lua_State *L) {
HANDLE hEvent = (HANDLE)lua_touserdata(L, 1);
+ Events.remove(hEvent);
+
int res = ::DestroyHookableEvent(hEvent);
lua_pushinteger(L, res);
@@ -48,6 +116,9 @@ static int lua_HookEvent(lua_State *L) HANDLE res = ::HookEventObjParam(name, CMLua::HookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
+ Hooks.insert(res);
+ HookRefs.insert(new HandleRefParam(L, res, ref));
+
return 1;
}
@@ -55,6 +126,16 @@ static int lua_UnhookEvent(lua_State *L) {
HANDLE hEvent = (HANDLE)lua_touserdata(L, 1);
+ Hooks.remove(hEvent);
+
+ HandleRefParam *param = (HandleRefParam*)HookRefs.find(hEvent);
+ if (param != NULL)
+ {
+ luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
+ HookRefs.remove(param);
+ delete param;
+ }
+
int res = ::UnhookEvent(hEvent);
lua_pushinteger(L, res);
@@ -75,6 +156,9 @@ static int lua_OnModulesLoaded(lua_State *L) HANDLE res = ::HookEventObjParam(ME_SYSTEM_MODULESLOADED, CMLua::HookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
+ Hooks.insert(res);
+ HookRefs.insert(new HandleRefParam(L, res, ref));
+
return 1;
}
@@ -92,6 +176,9 @@ static int lua_OnPreShutdown(lua_State *L) HANDLE res = ::HookEventObjParam(ME_SYSTEM_PRESHUTDOWN, CMLua::HookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
+ Hooks.insert(res);
+ HookRefs.insert(new HandleRefParam(L, res, ref));
+
return 1;
}
@@ -108,8 +195,7 @@ static INT_PTR ServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam, printf("%s\n", lua_tostring(L, -1));
INT_PTR res = (INT_PTR)lua_tointeger(L, 1);
-
- //luaL_unref(L, LUA_REGISTRYINDEX, ref);
+ lua_pushinteger(L, res);
return res;
}
@@ -130,6 +216,9 @@ static int lua_CreateServiceFunction(lua_State *L) HANDLE res = ::CreateServiceFunctionObjParam(name, ServiceFunctionObjParam, L, ref);
lua_pushlightuserdata(L, res);
+ Services.insert(res);
+ ServiceRefs.insert(new HandleRefParam(L, res, ref));
+
return 1;
}
@@ -137,6 +226,16 @@ static int lua_DestroyServiceFunction(lua_State *L) {
HANDLE hService = (HANDLE)lua_touserdata(L, 1);
+ Services.remove(hService);
+
+ HandleRefParam *param = (HandleRefParam*)ServiceRefs.find(hService);
+ if (param != NULL)
+ {
+ luaL_unref(param->L, LUA_REGISTRYINDEX, param->ref);
+ ServiceRefs.remove(param);
+ delete param;
+ }
+
int res = ::DestroyServiceFunction(hService);
lua_pushinteger(L, res);
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index f42f0fecdb..90c5e302c6 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -41,12 +41,13 @@ void CMLua::Unload() {
mir_writeLogT(hLogger, _T("Unloading lua engine\n"));
- if (L)
- lua_close(L);
KillModuleMenus(hScriptsLangpack);
+ KillModuleServices();
+ KillModuleEventHooks();
//KillModuleSubclassing
- //KillModuleServices
- //KillModuleEventHooks
+
+ if (L)
+ lua_close(L);
}
void CMLua::Reload()
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index f98d8f0d4e..81bdbdb177 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -8,6 +8,9 @@ private: HANDLE hLogger;
CMLuaConsole *console;
+ static void KillModuleServices();
+ static void KillModuleEventHooks();
+
void Load();
void Unload();
diff --git a/plugins/MirLua/src/mlua_console.cpp b/plugins/MirLua/src/mlua_console.cpp index 1a4fc5da1b..428e43f585 100644 --- a/plugins/MirLua/src/mlua_console.cpp +++ b/plugins/MirLua/src/mlua_console.cpp @@ -1,6 +1,6 @@ #include "stdafx.h"
-BOOL WINAPI ConsoleHandler(DWORD cEvent)
+BOOL WINAPI ConsoleHandler(DWORD)
{
return TRUE;
}
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index 986c83b880..bd01214dc9 100644 --- a/plugins/MirLua/src/version.h +++ b/plugins/MirLua/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|