summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_protocols.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-09-24 19:45:18 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-09-24 19:45:18 +0000
commita0d2cd360477acf24963e479773588b01f3d8a10 (patch)
treed6e208ebf7b83d49396f35b64a2f151ab2661478 /plugins/MirLua/src/m_protocols.cpp
parentac49502476c6319e6d942d5815405b961713b663 (diff)
MirLua: added OnProtoAck and OnReceiveMessage in m_protocols
git-svn-id: http://svn.miranda-ng.org/main/trunk@15440 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_protocols.cpp')
-rw-r--r--plugins/MirLua/src/m_protocols.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp
index c095f44470..5f82e69da2 100644
--- a/plugins/MirLua/src/m_protocols.cpp
+++ b/plugins/MirLua/src/m_protocols.cpp
@@ -1,5 +1,7 @@
#include "stdafx.h"
+HANDLE hRecvMessage = NULL;
+
static void MapToTable(lua_State *L, const PROTOCOLDESCRIPTOR* pd)
{
lua_newtable(L);
@@ -187,6 +189,120 @@ static int lua_EnumAccounts(lua_State *L)
return 1;
}
+int ProtoAckHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
+{
+ lua_State *L = (lua_State*)obj;
+
+ int ref = param;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+
+ lua_pushnumber(L, wParam);
+
+ ACKDATA *ack = (ACKDATA*)lParam;
+
+ lua_newtable(L);
+ lua_pushliteral(L, "Module");
+ lua_pushstring(L, ptrA(mir_utf8encode(ack->szModule)));
+ lua_settable(L, -3);
+ lua_pushliteral(L, "hContact");
+ lua_pushinteger(L, ack->hContact);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "Type");
+ lua_pushinteger(L, ack->type);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "Result");
+ lua_pushinteger(L, ack->result);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "hProcess");
+ lua_pushlightuserdata(L, ack->hProcess);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "lParam");
+ lua_pushnumber(L, ack->lParam);
+ lua_settable(L, -3);
+
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+
+ int res = (int)lua_tointeger(L, 1);
+
+ return res;
+}
+
+static int lua_OnProtoAck(lua_State *L)
+{
+ if (!lua_isfunction(L, 1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
+ lua_pushvalue(L, 1);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ 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;
+}
+
+int RecvMessageHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param)
+{
+ lua_State *L = (lua_State*)obj;
+
+ int ref = param;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+
+ lua_pushnumber(L, wParam);
+
+ CCSDATA *ccs = (CCSDATA*)lParam;
+ PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
+
+ lua_newtable(L);
+ lua_pushliteral(L, "hContact");
+ lua_pushinteger(L, ccs->hContact);
+ lua_settable(L, -3);
+ lua_pushliteral(L, "Message");
+ lua_pushstring(L, pre->szMessage);
+ lua_settable(L, -3);
+
+ if (lua_pcall(L, 2, 1, 0))
+ printf("%s\n", lua_tostring(L, -1));
+
+ int res = (int)lua_tointeger(L, 1);
+
+ return res;
+}
+
+static int lua_OnReceiveMessage(lua_State *L)
+{
+ if (!lua_isfunction(L, 1))
+ {
+ lua_pushlightuserdata(L, NULL);
+ return 1;
+ }
+
+ lua_pushvalue(L, 1);
+ int ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ 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;
+}
+
+INT_PTR FilterRecvMessage(WPARAM wParam, LPARAM lParam)
+{
+ NotifyEventHooks(hRecvMessage, wParam, lParam);
+
+ return Proto_ChainRecv(wParam, (CCSDATA*)lParam);
+}
+
static luaL_Reg protocolsApi[] =
{
{ "GetProto", lua_GetProto },
@@ -197,6 +313,9 @@ static luaL_Reg protocolsApi[] =
{ "AllAccounts", lua_AllAccounts },
{ "EnumAccounts", lua_EnumAccounts },
+ { "OnProtoAck", lua_OnProtoAck },
+ { "OnReceiveMessage", lua_OnReceiveMessage },
+
{ NULL, NULL }
};