diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-11-25 18:17:36 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-11-25 18:17:36 +0000 |
commit | f155980e50b5670593eb0857a061d16f708a362f (patch) | |
tree | dbf0c648b8db4eae88d7ce70bf3f8e7a4edf9ff9 | |
parent | b4132ae8daa7cb96ef49eca4827380c0e629a031 (diff) |
MirLua: removed needless stuff
git-svn-id: http://svn.miranda-ng.org/main/trunk@15778 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/MirLua/src/m_chat.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 89 | ||||
-rw-r--r-- | plugins/MirLua/src/m_database.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/m_message.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/m_msg_buttonsbar.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 2 | ||||
-rw-r--r-- | plugins/MirLua/src/m_toptoolbar.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.cpp | 36 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua.h | 9 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 35 |
10 files changed, 70 insertions, 106 deletions
diff --git a/plugins/MirLua/src/m_chat.cpp b/plugins/MirLua/src/m_chat.cpp index cc32d26d78..7a2428c67f 100644 --- a/plugins/MirLua/src/m_chat.cpp +++ b/plugins/MirLua/src/m_chat.cpp @@ -71,7 +71,6 @@ static int lua_OnReceiveEvent(lua_State *L) HANDLE res = ::HookEventObjParam(ME_GC_HOOK_EVENT, GCHookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index d0986da3c6..133dfb119f 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -4,39 +4,14 @@ static int lua_CreateHookableEvent(lua_State *L) {
const char *name = luaL_checkstring(L, 1);
- HANDLE res = ::CreateHookableEvent(name);
- if (!res)
+ HANDLE res = CreateHookableEvent(name);
+ if (res == NULL)
{
lua_pushnil(L);
+
return 1;
}
-
lua_pushlightuserdata(L, res);
- CMLua::Events.insert(res);
-
- return 1;
-}
-
-static int lua_DestroyHookableEvent(lua_State *L)
-{
- HANDLE hEvent = lua_touserdata(L, 1);
-
- int res = ::DestroyHookableEvent(hEvent);
- if (!res)
- CMLua::Events.remove(hEvent);
- lua_pushboolean(L, !res);
-
- return 1;
-}
-
-static int lua_NotifyEventHooks(lua_State *L)
-{
- HANDLE hEvent = lua_touserdata(L, 1);
- WPARAM wParam = luaM_towparam(L, 2);
- LPARAM lParam = luaM_tolparam(L, 3);
-
- int res = ::NotifyEventHooks(hEvent, wParam, lParam);
- lua_pushboolean(L, res != -1);
return 1;
}
@@ -48,14 +23,20 @@ int HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param) int ref = param;
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
- lua_pushlightuserdata(L, (void*)wParam);
- lua_pushlightuserdata(L, (void*)lParam);
+ if (wParam)
+ lua_pushlightuserdata(L, (void*)wParam);
+ else
+ lua_pushnil(L);
+
+ if (lParam)
+ lua_pushlightuserdata(L, (void*)lParam);
+ else
+ lua_pushnil(L);
+
if (lua_pcall(L, 2, 1, 0))
CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1));
- int res = (int)lua_tointeger(L, 1);
-
- return res;
+ return lua_tointeger(L, 1);
}
static int lua_HookEvent(lua_State *L)
@@ -67,16 +48,16 @@ static int lua_HookEvent(lua_State *L) int ref = luaL_ref(L, LUA_REGISTRYINDEX);
HANDLE res = ::HookEventObjParam(name, HookEventObjParam, L, ref);
- if (!res)
+ if (res == NULL)
{
luaL_unref(L, LUA_REGISTRYINDEX, ref);
lua_pushnil(L);
+
return 1;
}
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
-
+
lua_pushlightuserdata(L, res);
return 1;
@@ -84,13 +65,12 @@ static int lua_HookEvent(lua_State *L) static int lua_UnhookEvent(lua_State *L)
{
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
HANDLE hEvent = lua_touserdata(L, 1);
- int res = ::UnhookEvent(hEvent);
+ int res = UnhookEvent(hEvent);
if (!res)
{
- CMLua::Hooks.remove(hEvent);
-
HandleRefParam *param = (HandleRefParam*)CMLua::HookRefs.find(hEvent);
if (param != NULL)
{
@@ -104,6 +84,32 @@ static int lua_UnhookEvent(lua_State *L) return 1;
}
+static int lua_NotifyEventHooks(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+ HANDLE hEvent = lua_touserdata(L, 1);
+ WPARAM wParam = luaM_towparam(L, 2);
+ LPARAM lParam = luaM_tolparam(L, 3);
+
+ int res = NotifyEventHooks(hEvent, wParam, lParam);
+ lua_pushboolean(L, res != -1);
+
+ return 1;
+}
+
+static int lua_DestroyHookableEvent(lua_State *L)
+{
+ luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+ HANDLE hEvent = lua_touserdata(L, 1);
+
+ int res = DestroyHookableEvent(hEvent);
+ lua_pushboolean(L, !res);
+
+ return 1;
+}
+
+/***********************************************/
+
INT_PTR CreateServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
{
lua_State *L = (lua_State*)obj;
@@ -138,7 +144,6 @@ static int lua_CreateServiceFunction(lua_State *L) return 1;
}
- CMLua::Services.insert(res);
CMLua::ServiceRefs.insert(new HandleRefParam(L, res, ref));
lua_pushlightuserdata(L, res);
@@ -150,8 +155,6 @@ static int lua_DestroyServiceFunction(lua_State *L) {
HANDLE hService = lua_touserdata(L, 1);
- CMLua::Services.remove(hService);
-
HandleRefParam *param = (HandleRefParam*)CMLua::ServiceRefs.find(hService);
if (param != NULL)
{
@@ -262,7 +265,7 @@ luaL_Reg coreApi[] = { "UnhookEvent", lua_UnhookEvent },
{ "CreateServiceFunction", lua_CreateServiceFunction },
- { "DestroyServiceFunction", lua_DestroyServiceFunction },
+ //{ "DestroyServiceFunction", lua_DestroyServiceFunction },
{ "ServiceExists", lua_ServiceExists },
{ "CallService", lua_CallService },
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 886be02dd6..d8e980e2ca 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -498,7 +498,6 @@ static int lua_OnSettingChanged(lua_State *L) HANDLE res = ::HookEventObjParam(ME_DB_CONTACT_SETTINGCHANGED, SettingsChangedHookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp index 3d0848d523..0db063f684 100644 --- a/plugins/MirLua/src/m_message.cpp +++ b/plugins/MirLua/src/m_message.cpp @@ -117,7 +117,6 @@ static int lua_OnMsgWindowEvent(lua_State *L) HANDLE res = ::HookEventObjParam(ME_MSG_WINDOWEVENT, MsgWindowEventHookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp index a798c076c8..25245b7321 100644 --- a/plugins/MirLua/src/m_msg_buttonsbar.cpp +++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp @@ -173,7 +173,6 @@ static int lua_OnMsgToolBarButtonPressed(lua_State *L) HANDLE res = ::HookEventObjParam(ME_MSG_BUTTONPRESSED, ButtonPressedHookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index 987f72a571..222a766129 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -246,7 +246,6 @@ static int lua_OnProtoAck(lua_State *L) HANDLE res = ::HookEventObjParam(ME_PROTO_ACK, ProtoAckHookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
@@ -296,7 +295,6 @@ static int lua_OnReceiveMessage(lua_State *L) HANDLE res = ::HookEventObjParam(MODULE PSR_MESSAGE, RecvMessageHookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
diff --git a/plugins/MirLua/src/m_toptoolbar.cpp b/plugins/MirLua/src/m_toptoolbar.cpp index d850c9429b..b990dcf8e0 100644 --- a/plugins/MirLua/src/m_toptoolbar.cpp +++ b/plugins/MirLua/src/m_toptoolbar.cpp @@ -130,7 +130,6 @@ static int lua_OnTopToolBarLoaded(lua_State *L) HANDLE res = ::HookEventObjParam(ME_TTB_MODULELOADED, CMLua::HookEventObjParam, L, ref);
lua_pushlightuserdata(L, res);
- CMLua::Hooks.insert(res);
CMLua::HookRefs.insert(new HandleRefParam(L, res, ref));
return 1;
diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index c55cbe57f7..5a17246a5f 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -1,8 +1,8 @@ #include "stdafx.h"
-LIST<void> CMLua::Hooks(1, PtrKeySortT);
-LIST<void> CMLua::Events(1, PtrKeySortT);
-LIST<void> CMLua::Services(1, PtrKeySortT);
+//LIST<void> CMLua::Hooks(1, PtrKeySortT);
+//LIST<void> CMLua::Events(1, PtrKeySortT);
+//LIST<void> CMLua::Services(1, PtrKeySortT);
LIST<void> CMLua::HookRefs(1, HandleKeySortT);
LIST<void> CMLua::ServiceRefs(1, HandleKeySortT);
@@ -73,30 +73,16 @@ void CMLua::Unload() ::KillModuleHotkeys(hScriptsLangpack);
::KillObjectEventHooks(L);
::KillObjectServices(L);
- CMLua::KillModuleServices();
- CMLua::KillModuleEventHooks();
//KillModuleSubclassing
+ //CMLua::KillLuaRefs();
+
if (L)
lua_close(L);
}
-void CMLua::KillModuleEventHooks()
+void CMLua::KillLuaRefs()
{
- 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];
@@ -107,16 +93,6 @@ void CMLua::KillModuleEventHooks() delete param;
}
}
-}
-
-void CMLua::KillModuleServices()
-{
- while (Services.getCount())
- {
- HANDLE hService = Services[0];
- Services.remove(0);
- DestroyServiceFunction(hService);
- }
while (ServiceRefs.getCount())
{
diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index 6c8796b4ff..a2b7301baa 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -15,13 +15,12 @@ class CMLua private:
lua_State *L;
- static void KillModuleEventHooks();
- static void KillModuleServices();
+ static void KillLuaRefs();
public:
- static LIST<void> Hooks;
- static LIST<void> Events;
- static LIST<void> Services;
+ //static LIST<void> Hooks;
+ //static LIST<void> Events;
+ //static LIST<void> Services;
static LIST<void> HookRefs;
static LIST<void> ServiceRefs;
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index 9bfa298cca..3bd1298263 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -75,46 +75,39 @@ bool luaM_toboolean(lua_State *L, int idx) WPARAM luaM_towparam(lua_State *L, int idx)
{
- WPARAM wParam = NULL;
switch (lua_type(L, idx))
{
case LUA_TBOOLEAN:
- wParam = lua_toboolean(L, idx);
- break;
+ return lua_toboolean(L, idx);
case LUA_TNUMBER:
- wParam = lua_tonumber(L, idx);
- break;
+ return lua_tonumber(L, idx);
case LUA_TSTRING:
- wParam = (WPARAM)lua_tostring(L, idx);
+ return (WPARAM)lua_tostring(L, idx);
break;
- case LUA_TUSERDATA:
+ //case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
- wParam = (WPARAM)lua_touserdata(L, idx);
- break;
+ return (WPARAM)lua_touserdata(L, idx);
+ default:
+ return NULL;
}
- return wParam;
}
LPARAM luaM_tolparam(lua_State *L, int idx)
{
- LPARAM lParam = NULL;
switch (lua_type(L, idx))
{
case LUA_TBOOLEAN:
- lParam = lua_toboolean(L, idx);
- break;
+ return lua_toboolean(L, idx);
case LUA_TNUMBER:
- lParam = lua_tonumber(L, idx);
- break;
+ return lua_tonumber(L, idx);
case LUA_TSTRING:
- lParam = (LPARAM)lua_tostring(L, idx);
- break;
- case LUA_TUSERDATA:
+ return (LPARAM)lua_tostring(L, idx);
+ //case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
- lParam = (LPARAM)lua_touserdata(L, idx);
- break;
+ return (LPARAM)lua_touserdata(L, idx);
+ default:
+ return NULL;
}
- return lParam;
}
int luaM_totable(lua_State *L)
|