summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src/m_chat.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-09-28 12:33:12 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-09-28 12:33:12 +0000
commitbc2780159221f9d9ef825e41d16cfdaa23c956b2 (patch)
treefa5de82fcb4f2818fd2293a303dc6846ab1cf928 /plugins/MirLua/src/m_chat.cpp
parent5400fb4d896b699cc1bcfb960fdc037e0703343a (diff)
MirLua: added m_chat module
git-svn-id: http://svn.miranda-ng.org/main/trunk@15465 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_chat.cpp')
-rw-r--r--plugins/MirLua/src/m_chat.cpp86
1 files changed, 86 insertions, 0 deletions
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;
+}