From e2cbb427d5225aac2af633dabc0f929d1257fcc8 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 19 Sep 2015 21:17:17 +0000 Subject: MirLua: added OnMsgWindowEvent to m_message git-svn-id: http://svn.miranda-ng.org/main/trunk@15405 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_message.cpp | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'plugins/MirLua/src/m_message.cpp') diff --git a/plugins/MirLua/src/m_message.cpp b/plugins/MirLua/src/m_message.cpp index 87e8e1a353..e53403d2bc 100644 --- a/plugins/MirLua/src/m_message.cpp +++ b/plugins/MirLua/src/m_message.cpp @@ -49,11 +49,66 @@ static int lua_Send(lua_State *L) return 1; } +int MsgWindowEventHookEventObjParam(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); + + MessageWindowEventData *ev = (MessageWindowEventData*)lParam; + + lua_newtable(L); + lua_pushliteral(L, "Module"); + lua_pushstring(L, ptrA(mir_utf8encode(ev->szModule))); + lua_settable(L, -3); + lua_pushliteral(L, "Type"); + lua_pushinteger(L, ev->uType); + lua_settable(L, -3); + lua_pushliteral(L, "hContact"); + lua_pushinteger(L, ev->hContact); + lua_settable(L, -3); + lua_pushliteral(L, "Flags"); + lua_pushinteger(L, ev->uFlags); + 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_OnMsgWindowEvent(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_MSG_WINDOWEVENT, MsgWindowEventHookEventObjParam, L, ref); + lua_pushlightuserdata(L, res); + + CMLua::Hooks.insert(res); + CMLua::HookRefs.insert(new HandleRefParam(L, res, ref)); + + return 1; +} + static luaL_Reg messageApi[] = { { "Paste", lua_Paste }, { "Send", lua_Send }, + { "OnMsgWindowEvent", lua_OnMsgWindowEvent }, + { NULL, NULL } }; -- cgit v1.2.3