From 8ecb995a281008dbbc83ba8ea04ef28dbdc3d2e2 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 11 Jun 2015 14:02:29 +0000 Subject: MirLua: added ModifyMenuItem to m_genmenu git-svn-id: http://svn.miranda-ng.org/main/trunk@14116 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_genmenu.cpp | 45 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'plugins/MirLua/src') diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp index 43e1b2a36f..83001cd27b 100644 --- a/plugins/MirLua/src/m_genmenu.cpp +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -5,27 +5,33 @@ static CLISTMENUITEM* MakeMenuItem(lua_State *L) CLISTMENUITEM *pmi = (CLISTMENUITEM*)mir_calloc(sizeof(CLISTMENUITEM)); pmi->cbSize = sizeof(CLISTMENUITEM); - lua_getfield(L, 1, "Name"); + lua_pushstring(L, "Name"); + lua_gettable(L, -2); pmi->pszName = LPGEN((char*)luaL_checkstring(L, -1)); lua_pop(L, 1); - lua_getfield(L, 1, "Flags"); + lua_pushstring(L, "Flags"); + lua_gettable(L, -2); pmi->flags = lua_tointeger(L, -1); lua_pop(L, 1); - lua_getfield(L, 1, "Position"); + lua_pushstring(L, "Position"); + lua_gettable(L, -2); pmi->position = lua_tointeger(L, -1); lua_pop(L, 1); - lua_getfield(L, 1, "Icon"); + lua_pushstring(L, "Icon"); + lua_gettable(L, -2); pmi->icolibItem = (HANDLE)lua_touserdata(L, -1); lua_pop(L, 1); - lua_getfield(L, 1, "Service"); + lua_pushstring(L, "Service"); + lua_gettable(L, -2); pmi->pszService = (char*)lua_tostring(L, -1); lua_pop(L, 1); - lua_getfield(L, 1, "Parent"); + lua_pushstring(L, "Parent"); + lua_gettable(L, -2); pmi->hParentMenu = (HGENMENU)lua_touserdata(L, -1); lua_pop(L, 1); @@ -40,12 +46,8 @@ static int lua_AddMainMenuItem(lua_State *L) return 1; } - lua_settop(L, 1); - mir_ptr pmi(MakeMenuItem(L)); - lua_pop(L, 1); - HGENMENU res = ::Menu_AddMainMenuItem(pmi); lua_pushlightuserdata(L, res); @@ -60,18 +62,32 @@ static int lua_AddContactMenuItem(lua_State *L) return 1; } - lua_settop(L, 1); - mir_ptr pmi(MakeMenuItem(L)); - lua_pop(L, 1); - HGENMENU res = ::Menu_AddContactMenuItem(pmi); lua_pushlightuserdata(L, res); return 1; } +static int lua_ModifyMenuItem(lua_State *L) +{ + HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); + + if (lua_type(L, 2) != LUA_TTABLE) + { + lua_pushlightuserdata(L, 0); + return 1; + } + + mir_ptr pmi(MakeMenuItem(L)); + + INT_PTR res = ::CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuItem, (LPARAM)pmi); + lua_pushinteger(L, res); + + return 1; +} + static int lua_RemoveMenuItem(lua_State *L) { HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); @@ -86,6 +102,7 @@ static luaL_Reg genmenuApi[] = { { "AddMainMenuItem", lua_AddMainMenuItem }, { "AddContactMenuItem", lua_AddContactMenuItem }, + { "ModifyMenuItem", lua_ModifyMenuItem }, { "RemoveMenuItem", lua_RemoveMenuItem }, { NULL, NULL } -- cgit v1.2.3