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/MirLua.vcxproj | 2 +- plugins/MirLua/MirLua.vcxproj.filters | 687 +++++++++++++++++++++++++++++++- plugins/MirLua/src/m_chat.cpp | 69 +++- plugins/MirLua/src/m_core.cpp | 27 +- plugins/MirLua/src/m_database.cpp | 76 ++++ plugins/MirLua/src/m_message.cpp | 51 +++ plugins/MirLua/src/m_msg_buttonsbar.cpp | 53 ++- plugins/MirLua/src/m_protocols.cpp | 105 +++++ plugins/MirLua/src/m_toptoolbar.cpp | 2 + plugins/MirLua/src/mlua.cpp | 6 +- plugins/MirLua/src/mlua_utils.cpp | 46 +++ plugins/MirLua/src/stdafx.h | 6 + plugins/MirLua/src/version.h | 4 +- 13 files changed, 1121 insertions(+), 13 deletions(-) (limited to 'plugins') diff --git a/plugins/MirLua/MirLua.vcxproj b/plugins/MirLua/MirLua.vcxproj index 342893c008..57e34980c1 100644 --- a/plugins/MirLua/MirLua.vcxproj +++ b/plugins/MirLua/MirLua.vcxproj @@ -37,4 +37,4 @@ - + \ No newline at end of file diff --git a/plugins/MirLua/MirLua.vcxproj.filters b/plugins/MirLua/MirLua.vcxproj.filters index a8ab01c0e5..9388fdfa0e 100644 --- a/plugins/MirLua/MirLua.vcxproj.filters +++ b/plugins/MirLua/MirLua.vcxproj.filters @@ -1,4 +1,689 @@  - + + + Source Files + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + Source Files + + + + + + + + + + + + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + Header Files + + + + + + + + + + + + + + + + Resource Files + + + + Resource Files + + + + + + Resource Files + + + + + Resource Files + + + + + Resource Files + + + + + \ No newline at end of file diff --git a/plugins/MirLua/src/m_chat.cpp b/plugins/MirLua/src/m_chat.cpp index dad9047100..fb3b9d9ad9 100644 --- a/plugins/MirLua/src/m_chat.cpp +++ b/plugins/MirLua/src/m_chat.cpp @@ -7,7 +7,11 @@ int GCHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param) int ref = param; lua_rawgeti(L, LUA_REGISTRYINDEX, ref); - lua_pushnumber(L, wParam); + WPARAM* wParam_ptr = (WPARAM*)lua_newuserdata(L, sizeof(WPARAM)); + *wParam_ptr = wParam; + + LPARAM* lParam_ptr = (LPARAM*)lua_newuserdata(L, sizeof(LPARAM)); + *lParam_ptr = lParam; GCEVENT *gce = (GCEVENT*)lParam; @@ -53,6 +57,8 @@ int GCHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param) static int lua_OnReceiveEvent(lua_State *L) { + ObsoleteMethod(L, "Use m.HookEvent instead"); + if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); @@ -78,9 +84,70 @@ static luaL_Reg chatApi[] = { NULL, NULL } }; +#define MT_GCEVENT "GCEVENT" + +static int gce__init(lua_State *L) +{ + GCEVENT *udata = (GCEVENT*)lua_touserdata(L, 1); + if (udata == NULL) + { + lua_pushnil(L); + return 1; + } + + GCEVENT **gce = (GCEVENT**)lua_newuserdata(L, sizeof(GCEVENT*)); + *gce = udata; + + luaL_setmetatable(L, MT_GCEVENT); + + return 1; +} + +static int gce__index(lua_State *L) +{ + GCEVENT *gce = (GCEVENT*)luaL_checkudata(L, 1, MT_GCEVENT); + const char *key = luaL_checkstring(L, 2); + + if (mir_strcmpi(key, "Module")) + lua_pushstring(L, gce->pDest->pszModule); + if (mir_strcmpi(key, "Id")) + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + if (mir_strcmpi(key, "Type")) + lua_pushinteger(L, gce->pDest->iType); + if (mir_strcmpi(key, "Timestamp")) + lua_pushnumber(L, gce->time); + if (mir_strcmpi(key, "IsMe")) + lua_pushboolean(L, gce->bIsMe); + if (mir_strcmpi(key, "Flags")) + lua_pushinteger(L, gce->dwFlags); + if (mir_strcmpi(key, "Uid")) + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + if (mir_strcmpi(key, "Nick")) + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + if (mir_strcmpi(key, "Status")) + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + if (mir_strcmpi(key, "Text")) + lua_pushstring(L, ptrA(mir_utf8encodeT(gce->pDest->ptszID))); + else + lua_pushnil(L); + + return 1; +} + +static const luaL_Reg gceMeta[] = +{ + { "__init", gce__init }, + { "__index", gce__index }, + { NULL, NULL } +}; + LUAMOD_API int luaopen_m_chat(lua_State *L) { luaL_newlib(L, chatApi); + luaL_newmetatable(L, MT_GCEVENT); + luaL_setfuncs(L, gceMeta, 0); + lua_pop(L, 1); + return 1; } diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index 6a5b4cb2d0..b2f6beda2a 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -36,6 +36,23 @@ static int lua_NotifyEventHooks(lua_State *L) return 1; } +int HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param) +{ + lua_State *L = (lua_State*)obj; + + int ref = param; + lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + + lua_pushlightuserdata(L, (void*)wParam); + lua_pushlightuserdata(L, (void*)lParam); + if (lua_pcall(L, 2, 1, 0)) + CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); + + int res = (int)lua_tointeger(L, 1); + + return res; +} + static int lua_HookEvent(lua_State *L) { const char *name = luaL_checkstring(L, 1); @@ -49,7 +66,7 @@ static int lua_HookEvent(lua_State *L) lua_pushvalue(L, 2); int ref = luaL_ref(L, LUA_REGISTRYINDEX); - HANDLE res = ::HookEventObjParam(name, CMLua::HookEventObjParam, L, ref); + HANDLE res = ::HookEventObjParam(name, HookEventObjParam, L, ref); lua_pushlightuserdata(L, res); CMLua::Hooks.insert(res); @@ -78,15 +95,15 @@ static int lua_UnhookEvent(lua_State *L) return 1; } -static INT_PTR ServiceFunctionObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM param) +INT_PTR CreateServiceFunctionObjParam(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); - lua_pushnumber(L, lParam); + lua_pushlightuserdata(L, (void*)wParam); + lua_pushlightuserdata(L, (void*)lParam); if (lua_pcall(L, 2, 1, 0)) CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); @@ -109,7 +126,7 @@ static int lua_CreateServiceFunction(lua_State *L) lua_pushvalue(L, 2); int ref = luaL_ref(L, LUA_REGISTRYINDEX); - HANDLE res = ::CreateServiceFunctionObjParam(name, ServiceFunctionObjParam, L, ref); + HANDLE res = ::CreateServiceFunctionObjParam(name, CreateServiceFunctionObjParam, L, ref); lua_pushlightuserdata(L, res); CMLua::Services.insert(res); diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 9454d87664..bfbc986f55 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -480,6 +480,8 @@ static int SettingsChangedHookEventObjParam(void *obj, WPARAM wParam, LPARAM lPa static int lua_OnSettingChanged(lua_State *L) { + ObsoleteMethod(L, "Use m.HookEvent instead"); + if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); @@ -500,6 +502,8 @@ static int lua_OnSettingChanged(lua_State *L) static int lua_DecodeDBCONTACTWRITESETTING(lua_State *L) { + ObsoleteMethod(L, "Use totable(x, \"DBCONTACTWRITESETTING\") instead"); + DBCONTACTWRITESETTING *pDBCWS = (DBCONTACTWRITESETTING*)lua_tointeger(L, 1); lua_newtable(L); @@ -575,9 +579,81 @@ static luaL_Reg databaseApi[] = { NULL, NULL } }; +#define MT_DBCONTACTWRITESETTING "DBCONTACTWRITESETTING" + +static int dbcw__init(lua_State *L) +{ + DBCONTACTWRITESETTING *udata = (DBCONTACTWRITESETTING*)lua_touserdata(L, 1); + if (udata == NULL) + { + lua_pushnil(L); + return 1; + } + + DBCONTACTWRITESETTING **dbcw = (DBCONTACTWRITESETTING**)lua_newuserdata(L, sizeof(DBCONTACTWRITESETTING*)); + *dbcw = udata; + + luaL_setmetatable(L, MT_DBCONTACTWRITESETTING); + + return 1; +} + +static int dbcw__index(lua_State *L) +{ + DBCONTACTWRITESETTING *dbcw = (DBCONTACTWRITESETTING*)luaL_checkudata(L, 1, MT_DBCONTACTWRITESETTING); + const char *key = luaL_checkstring(L, 2); + + if (mir_strcmpi(key, "Module")) + lua_pushstring(L, dbcw->szModule); + if (mir_strcmpi(key, "Setting")) + lua_pushstring(L, dbcw->szSetting); + if (mir_strcmpi(key, "Value")) + { + switch (dbcw->value.type) + { + case DBVT_BYTE: + lua_pushinteger(L, dbcw->value.bVal); + break; + case DBVT_WORD: + lua_pushinteger(L, dbcw->value.wVal); + break; + case DBVT_DWORD: + lua_pushnumber(L, dbcw->value.dVal); + break; + case DBVT_ASCIIZ: + lua_pushstring(L, ptrA(mir_utf8encode(dbcw->value.pszVal))); + break; + case DBVT_UTF8: + lua_pushstring(L, dbcw->value.pszVal); + break; + case DBVT_WCHAR: + lua_pushstring(L, ptrA(mir_utf8encodeW(dbcw->value.pwszVal))); + break; + default: + lua_pushnil(L); + } + } + else + lua_pushnil(L); + + return 1; +} + +static const luaL_Reg dbcwMeta[] = +{ + { "__init", dbcw__init }, + { "__index", dbcw__index }, + { NULL, NULL } +}; + + LUAMOD_API int luaopen_m_database(lua_State *L) { luaL_newlib(L, databaseApi); + luaL_newmetatable(L, MT_DBCONTACTWRITESETTING); + luaL_setfuncs(L, dbcwMeta, 0); + lua_pop(L, 1); + return 1; } 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; } diff --git a/plugins/MirLua/src/m_msg_buttonsbar.cpp b/plugins/MirLua/src/m_msg_buttonsbar.cpp index 3973badba7..b7824e78aa 100644 --- a/plugins/MirLua/src/m_msg_buttonsbar.cpp +++ b/plugins/MirLua/src/m_msg_buttonsbar.cpp @@ -132,7 +132,7 @@ int ButtonPressedHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPAR lua_rawgeti(L, LUA_REGISTRYINDEX, ref); lua_pushnumber(L, wParam); - + CustomButtonClickData *bcd = (CustomButtonClickData*)lParam; lua_newtable(L); @@ -159,6 +159,8 @@ int ButtonPressedHookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPAR static int lua_OnMsgToolBarButtonPressed(lua_State *L) { + ObsoleteMethod(L, "Use m.HookEvent instead"); + if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); @@ -210,9 +212,58 @@ static luaL_Reg msgbuttinsbarApi[] = { NULL, NULL } }; +#define MT_CUSTOMBUTTONCLICKDATA "CustomButtonClickData" + +static int bcd__init(lua_State *L) +{ + CustomButtonClickData *udata = (CustomButtonClickData*)lua_touserdata(L, 1); + if (udata == NULL) + { + lua_pushnil(L); + return 1; + } + + CustomButtonClickData **bcd = (CustomButtonClickData**)lua_newuserdata(L, sizeof(CustomButtonClickData*)); + *bcd = udata; + + luaL_setmetatable(L, MT_CUSTOMBUTTONCLICKDATA); + + return 1; +} + +static int bcd__index(lua_State *L) +{ + CustomButtonClickData *bcd = *(CustomButtonClickData**)luaL_checkudata(L, 1, MT_CUSTOMBUTTONCLICKDATA); + const char *key = lua_tostring(L, 2); + + if (!mir_strcmpi(key, "Module")) + lua_pushstring(L, ptrA(mir_utf8encode(bcd->pszModule))); + else if (!mir_strcmpi(key, "ButtonID")) + lua_pushinteger(L, bcd->dwButtonId); + else if (!mir_strcmpi(key, "hContact")) + lua_pushinteger(L, bcd->hContact); + else if (!mir_strcmpi(key, "Flags")) + lua_pushinteger(L, bcd->flags); + else + lua_pushnil(L); + + return 1; +} + +static luaL_Reg bcdMeta[] = +{ + { "__init", bcd__init }, + { "__index", bcd__index }, + { NULL, NULL } +}; + LUAMOD_API int luaopen_m_msg_buttonsbar(lua_State *L) { luaL_newlib(L, msgbuttinsbarApi); + + luaL_newmetatable(L, MT_CUSTOMBUTTONCLICKDATA); + luaL_setfuncs(L, bcdMeta, 0); + lua_pop(L, 1); return 1; } 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; } diff --git a/plugins/MirLua/src/m_toptoolbar.cpp b/plugins/MirLua/src/m_toptoolbar.cpp index be1739bfcc..3d2e888ac5 100644 --- a/plugins/MirLua/src/m_toptoolbar.cpp +++ b/plugins/MirLua/src/m_toptoolbar.cpp @@ -119,6 +119,8 @@ static int lua_RemoveButton(lua_State *L) static int lua_OnTopToolBarLoaded(lua_State *L) { + ObsoleteMethod(L, "Use m.HookEvent instead"); + if (!lua_isfunction(L, 1)) { lua_pushlightuserdata(L, NULL); diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index 6da603358d..15bd34fe2d 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -41,6 +41,8 @@ void CMLua::Load() lua_setfield(L, -2, "a"); lua_pushcclosure(L, luaM_toucs2, 0); lua_setfield(L, -2, "u"); + lua_pushcclosure(L, luaM_totable, 0); + lua_setfield(L, -2, "totable"); lua_pop(L, 1); lua_atpanic(L, luaM_atpanic); @@ -135,8 +137,8 @@ int CMLua::HookEventObjParam(void *obj, WPARAM wParam, LPARAM lParam, LPARAM par int ref = param; lua_rawgeti(L, LUA_REGISTRYINDEX, ref); - lua_pushnumber(L, wParam); - lua_pushnumber(L, lParam); + lua_pushlightuserdata(L, (void*)wParam); + lua_pushlightuserdata(L, (void*)lParam); if (lua_pcall(L, 2, 1, 0)) CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index 04c41a5c6e..558652ef35 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -115,4 +115,50 @@ LPARAM luaM_tolparam(lua_State *L, int idx) break; } return lParam; +} + +int luaM_totable(lua_State *L) +{ + const char *tname = luaL_checkstring(L, -1); + + luaL_getmetatable(L, tname); + lua_getfield(L, -1, "__init"); + lua_pushvalue(L, 1); + if (lua_pcall(L, 1, 1, 0)) + CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)lua_tostring(L, -1)); + + return 1; +} + +void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact) +{ + if (Miranda_Terminated()) + { + return; + } + + if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) + { + POPUPDATA ppd = { 0 }; + ppd.lchContact = hContact; + mir_strncpy(ppd.lpzContactName, caption, MAX_CONTACTNAME); + mir_strncpy(ppd.lpzText, message, MAX_SECONDLINE); + + if (!PUAddPopup(&ppd)) + return; + } + + ::MessageBoxA(NULL, message, caption, MB_OK | flags); +} + +void ObsoleteMethod(lua_State *L, const char *message) +{ + lua_Debug info; + lua_getstack(L, 0, &info); + lua_getinfo(L, "n", &info); + + char text[512]; + mir_snprintf(text, "%s is obsolete. %s", info.name, message); + CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)text); + ShowNotification(MODULE, text, MB_OK | MB_ICONWARNING, NULL); } \ No newline at end of file diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 61f968d6a4..2fd13a061d 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -106,8 +106,14 @@ int luaM_atpanic(lua_State *L); int luaM_toansi(lua_State *L); int luaM_toucs2(lua_State *L); +int luaM_totable(lua_State *L); + bool luaM_toboolean(lua_State *L, int idx); WPARAM luaM_towparam(lua_State *L, int idx); LPARAM luaM_tolparam(lua_State *L, int idx); +void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact); + +void ObsoleteMethod(lua_State *L, const char *message); + #endif //_COMMON_H_ diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index 7315656b63..086f2b7388 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 7 +#define __RELEASE_NUM 5 +#define __BUILD_NUM 0 #include -- cgit v1.2.3