From bc2780159221f9d9ef825e41d16cfdaa23c956b2 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 28 Sep 2015 12:33:12 +0000 Subject: MirLua: added m_chat module git-svn-id: http://svn.miranda-ng.org/main/trunk@15465 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_chat.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++ plugins/MirLua/src/version.h | 2 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 plugins/MirLua/src/m_chat.cpp (limited to 'plugins/MirLua/src') diff --git a/plugins/MirLua/src/m_chat.cpp b/plugins/MirLua/src/m_chat.cpp new file mode 100644 index 0000000000..dad9047100 --- /dev/null +++ b/plugins/MirLua/src/m_chat.cpp @@ -0,0 +1,86 @@ +#include "stdafx.h" + +int GCHookEventObjParam(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); + + GCEVENT *gce = (GCEVENT*)lParam; + + lua_newtable(L); + lua_pushliteral(L, "Module"); + lua_pushstring(L, gce->pDest->pszModule); + lua_settable(L, -3); + lua_pushliteral(L, "Id"); + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + lua_settable(L, -3); + lua_pushliteral(L, "Type"); + lua_pushinteger(L, gce->pDest->iType); + lua_settable(L, -3); + lua_pushliteral(L, "Timestamp"); + lua_pushnumber(L, gce->time); + lua_settable(L, -3); + lua_pushliteral(L, "IsMe"); + lua_pushboolean(L, gce->bIsMe); + lua_settable(L, -3); + lua_pushliteral(L, "Flags"); + lua_pushinteger(L, gce->dwFlags); + lua_settable(L, -3); + lua_pushliteral(L, "Uid"); + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + lua_settable(L, -3); + lua_pushliteral(L, "Nick"); + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + lua_settable(L, -3); + lua_pushliteral(L, "Status"); + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + lua_settable(L, -3); + lua_pushliteral(L, "Text"); + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + 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_OnReceiveEvent(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_GC_HOOK_EVENT, GCHookEventObjParam, L, ref); + lua_pushlightuserdata(L, res); + + CMLua::Hooks.insert(res); + CMLua::HookRefs.insert(new HandleRefParam(L, res, ref)); + + return 1; +} + +static luaL_Reg chatApi[] = +{ + { "OnReceiveEvent", lua_OnReceiveEvent }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_chat(lua_State *L) +{ + luaL_newlib(L, chatApi); + + return 1; +} diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index 1d725ca11a..7315656b63 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 4 -#define __BUILD_NUM 6 +#define __BUILD_NUM 7 #include -- cgit v1.2.3