From c99bbd2ef7f9fb2295ff2ec07bb690c4d7351a71 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 21 Oct 2015 18:29:50 +0000 Subject: 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 --- plugins/MirLua/src/m_message.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 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 2968b1aeda..1722671689 100644 --- a/plugins/MirLua/src/m_message.cpp +++ b/plugins/MirLua/src/m_message.cpp @@ -103,6 +103,8 @@ int MsgWindowEventHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPA static int lua_OnMsgWindowEvent(lua_State *L) { + ObsoleteMethod(L, "Use m.HookEvent instead"); + if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); @@ -131,9 +133,58 @@ static luaL_Reg messageApi[] = { NULL, NULL } }; +#define MT_MESSAGEWINDOWEVENTDATA "MessageWindowEventData" + +static int mwed__init(lua_State *L) +{ + MessageWindowEventData *udata = (MessageWindowEventData*)lua_touserdata(L, 1); + if (udata == NULL) + { + lua_pushnil(L); + return 1; + } + + MessageWindowEventData **mwed = (MessageWindowEventData**)lua_newuserdata(L, sizeof(MessageWindowEventData*)); + *mwed = udata; + + luaL_setmetatable(L, MT_MESSAGEWINDOWEVENTDATA); + + return 1; +} + +static int mwed__index(lua_State *L) +{ + MessageWindowEventData *mwed = *(MessageWindowEventData**)luaL_checkudata(L, 1, MT_MESSAGEWINDOWEVENTDATA); + const char *key = lua_tostring(L, 2); + + if (!mir_strcmpi(key, "Module")) + lua_pushstring(L, ptrA(mir_utf8encode(mwed->szModule))); + if (!mir_strcmpi(key, "Type")) + lua_pushinteger(L, mwed->uType); + if (!mir_strcmpi(key, "hContact")) + lua_pushinteger(L, mwed->hContact); + if (!mir_strcmpi(key, "Flags")) + lua_pushinteger(L, mwed->uFlags); + else + lua_pushnil(L); + + return 1; +} + +static luaL_Reg mwedMeta[] = +{ + { "__init", mwed__init }, + { "__index", mwed__index }, + { NULL, NULL } +}; + LUAMOD_API int luaopen_m_message(lua_State *L) { luaL_newlib(L, messageApi); + luaL_newmetatable(L, MT_MESSAGEWINDOWEVENTDATA); + luaL_setfuncs(L, mwedMeta, 0); + lua_pop(L, 1); + return 1; } -- cgit v1.2.3