diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-10-21 18:29:50 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-10-21 18:29:50 +0000 |
commit | c99bbd2ef7f9fb2295ff2ec07bb690c4d7351a71 (patch) | |
tree | a760bc80000499732a80034d32bdd02cb3e9b885 /plugins/MirLua/src/m_protocols.cpp | |
parent | dd4878e302ae384f7b51b9ef60ff3a06dbd11a11 (diff) |
MirLua:
- added totable to cast userdata to metatable
- all modules hooks are marked as obsolete
- version bumb
git-svn-id: http://svn.miranda-ng.org/main/trunk@15586 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src/m_protocols.cpp')
-rw-r--r-- | plugins/MirLua/src/m_protocols.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/plugins/MirLua/src/m_protocols.cpp b/plugins/MirLua/src/m_protocols.cpp index 5f82e69da2..05be204deb 100644 --- a/plugins/MirLua/src/m_protocols.cpp +++ b/plugins/MirLua/src/m_protocols.cpp @@ -230,6 +230,8 @@ int ProtoAckHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM pa static int lua_OnProtoAck(lua_State *L)
{
+ ObsoleteMethod(L, "Use m.HookEvent instead");
+
if (!lua_isfunction(L, 1))
{
lua_pushlightuserdata(L, NULL);
@@ -278,6 +280,8 @@ int RecvMessageHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM static int lua_OnReceiveMessage(lua_State *L)
{
+ ObsoleteMethod(L, "Use m.HookEvent instead");
+
if (!lua_isfunction(L, 1))
{
lua_pushlightuserdata(L, NULL);
@@ -319,9 +323,110 @@ static luaL_Reg protocolsApi[] = { NULL, NULL }
};
+#define MT_ACKDATA "ACKDATA"
+
+static int ack__init(lua_State *L)
+{
+ ACKDATA *udata = (ACKDATA*)lua_touserdata(L, 1);
+ if (udata == NULL)
+ {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ ACKDATA **ack = (ACKDATA**)lua_newuserdata(L, sizeof(ACKDATA*));
+ *ack = udata;
+
+ luaL_setmetatable(L, MT_ACKDATA);
+
+ return 1;
+}
+
+static int ack__index(lua_State *L)
+{
+ ACKDATA *ack = *(ACKDATA**)luaL_checkudata(L, 1, MT_ACKDATA);
+ const char *key = lua_tostring(L, 2);
+
+ if (!mir_strcmpi(key, "Module"))
+ lua_pushstring(L, ptrA(mir_utf8encode(ack->szModule)));
+ if (!mir_strcmpi(key, "hContact"))
+ lua_pushinteger(L, ack->hContact);
+ if (!mir_strcmpi(key, "Type"))
+ lua_pushinteger(L, ack->type);
+ if (!mir_strcmpi(key, "Result"))
+ lua_pushinteger(L, ack->result);
+ if (!mir_strcmpi(key, "hProcess"))
+ lua_pushlightuserdata(L, ack->hProcess);
+ if (!mir_strcmpi(key, "lParam"))
+ lua_pushnumber(L, ack->lParam);
+ else
+ lua_pushnil(L);
+
+ return 1;
+}
+
+static luaL_Reg ackMeta[] =
+{
+ { "__init", ack__init },
+ { "__index", ack__index },
+ { NULL, NULL }
+};
+
+#define MT_CCSDATA "CCSDATA"
+
+static int ccs__init(lua_State *L)
+{
+ CCSDATA *udata = (CCSDATA*)lua_touserdata(L, 1);
+ if (udata == NULL)
+ {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ CCSDATA **ccs = (CCSDATA**)lua_newuserdata(L, sizeof(CCSDATA*));
+ *ccs = udata;
+
+ luaL_setmetatable(L, MT_ACKDATA);
+
+ return 1;
+}
+
+static int ccs__index(lua_State *L)
+{
+ CCSDATA *ccs = *(CCSDATA**)luaL_checkudata(L, 1, MT_CCSDATA);
+ const char *key = lua_tostring(L, 2);
+
+ if (!mir_strcmpi(key, "hContact"))
+ lua_pushinteger(L, ccs->hContact);
+ if (!mir_strcmpi(key, "Message"))
+ {
+ PROTORECVEVENT *pre = (PROTORECVEVENT*)ccs->lParam;
+ lua_pushstring(L, pre->szMessage);
+ }
+ else
+ lua_pushnil(L);
+
+ return 1;
+}
+
+static luaL_Reg ccsMeta[] =
+{
+ { "__init", ccs__init },
+ { "__index", ccs__index },
+ { NULL, NULL }
+};
+
LUAMOD_API int luaopen_m_protocols(lua_State *L)
{
luaL_newlib(L, protocolsApi);
+ luaL_newmetatable(L, MT_ACKDATA);
+ luaL_setfuncs(L, ackMeta, 0);
+ lua_pop(L, 1);
+
+ luaL_newmetatable(L, MT_CCSDATA);
+ luaL_setfuncs(L, ccsMeta, 0);
+ lua_pop(L, 1);
+
return 1;
}
|