diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-06-11 09:39:17 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-06-11 09:39:17 +0000 |
commit | ba33f8bbdd9a2d8c6f45454e2174770f444ffa2f (patch) | |
tree | 55580ef62afcfe1e3706ebec09a232da783bd82f /plugins/MirLua | |
parent | 8f5721964ac7ee042e04776c722e459490061204 (diff) |
MirLua: reworked module m_genmenu
git-svn-id: http://svn.miranda-ng.org/main/trunk@14113 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua')
-rw-r--r-- | plugins/MirLua/docs/examples/menus.lua | 56 | ||||
-rw-r--r-- | plugins/MirLua/src/m_genmenu.cpp | 76 |
2 files changed, 93 insertions, 39 deletions
diff --git a/plugins/MirLua/docs/examples/menus.lua b/plugins/MirLua/docs/examples/menus.lua index 50e7e75cde..ee1ca258a8 100644 --- a/plugins/MirLua/docs/examples/menus.lua +++ b/plugins/MirLua/docs/examples/menus.lua @@ -3,39 +3,53 @@ local genmenu = require('m_genmenu') --- include m_icolib module local icolib = require('m_icolib') +local menuItem = +{ + -- required field + Name = "Menu item", + Flags = 0, + Position = 0, + Icon = nil, + Service = nil, + Parent = nil +} + --- Add icon for menu items local hIcon = icolib.AddIcon('testMenuIcon', 'Lua icon for menus') --- Add menu item to main menu --- @param name The name of menu item --- @param flags The flugs that determine behaviour of menu item (default 0) --- @param position The position of menu item in main menu (default 0) --- @param icon The handle of icon of menu item (default NULL) --- @param service The name of service which will be called (default '') --- @param hParentMenu The handle of parent menu (default 0) --- @return handle of menu item -genmenu.AddMainMenuItem('Main menu item', 0, 0, hIcon, 'Srv/MMI') +menuItem.Name = "Main menu item" +menuItem.Icon = hIcon +menuItem.Service = "Srv/MMI" +genmenu.AddMainMenuItem(menuItem) --- Add menu item to contact menu --- @param name The name of menu item --- @param flags The flugs that determine behaviour of menu item (default 0) --- @param position The position of menu item in main menu (default 0) --- @param icon The handle of icon of menu item (default NULL) --- @param service The name of service which will be called (default '') --- @param hParentMenu The handle of parent menu (default 0) --- @return handle of menu item -genmenu.AddContactMenuItem('Contact menu item', 0, 0, hIcon, 'Srv/CMI') +menuItem.Name = "Contact menu item" +menuItem.Service = "Srv/CMI" +genmenu.AddContactMenuItem(menuItem) --- Create the contact menu item which will be deleted below -local hMenuItem = genmenu.AddContactMenuItem('testRemove', 0, 0, 0, 'Srv/TestRemove') +menuItem.Name = "testRemove" +menuItem.Service = "Srv/TestRemove" +local hMenuItem = genmenu.AddContactMenuItem(menuItem) --- Remove menu item from parent menu --- @param handle The handle of menu item --- @return 0 on success genmenu.RemoveMenuItem(hMenuItem) --- Add root menu item local CMIF_ROOTHANDLE = 384 -local hRoot = genmenu.AddMainMenuItem('Main menu root', CMIF_ROOTHANDLE) +local hRoot = genmenu.AddMainMenuItem({ Name = "Main menu root", Flags = CMIF_ROOTHANDLE }) + +--- Add child menu item +menuItem.Name = "Main menu child" +menuItem.Flags = CMIF_ROOTHANDLE +menuItem.Service = 'Srv/SMI' +menuItem.Parent = hRoot +genmenu.AddMainMenuItem(menuItem) + --- Add child menu item -genmenu.AddMainMenuItem('Main menu child', CMIF_ROOTHANDLE, 0, nil, 'Srv/CMI', hRoot) +menuItem.Name = "Main menu child 2" +menuItem.Flags = CMIF_ROOTHANDLE +menuItem.Service = 'Srv/SMI' +menuItem.Parent = "&Help" +genmenu.AddMainMenuItem(menuItem) diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp index 064758da2e..43e1b2a36f 100644 --- a/plugins/MirLua/src/m_genmenu.cpp +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -1,16 +1,52 @@ #include "stdafx.h"
+static CLISTMENUITEM* MakeMenuItem(lua_State *L)
+{
+ CLISTMENUITEM *pmi = (CLISTMENUITEM*)mir_calloc(sizeof(CLISTMENUITEM));
+ pmi->cbSize = sizeof(CLISTMENUITEM);
+
+ lua_getfield(L, 1, "Name");
+ pmi->pszName = LPGEN((char*)luaL_checkstring(L, -1));
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "Flags");
+ pmi->flags = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "Position");
+ pmi->position = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "Icon");
+ pmi->icolibItem = (HANDLE)lua_touserdata(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "Service");
+ pmi->pszService = (char*)lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ lua_getfield(L, 1, "Parent");
+ pmi->hParentMenu = (HGENMENU)lua_touserdata(L, -1);
+ lua_pop(L, 1);
+
+ return pmi;
+}
+
static int lua_AddMainMenuItem(lua_State *L)
{
- CLISTMENUITEM mi = { sizeof(mi) };
- mi.pszName = LPGEN((char*)luaL_checkstring(L, 1));
- mi.flags = lua_tointeger(L, 2);
- mi.position = lua_tointeger(L, 3);
- mi.icolibItem = (HANDLE)lua_touserdata(L, 4);
- mi.pszService = (char*)lua_tostring(L, 5);
- mi.hParentMenu = (HGENMENU)lua_touserdata(L, 6);
-
- HGENMENU res = ::Menu_AddMainMenuItem(&mi);
+ if (lua_type(L, 1) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ lua_settop(L, 1);
+
+ mir_ptr<CLISTMENUITEM> pmi(MakeMenuItem(L));
+
+ lua_pop(L, 1);
+
+ HGENMENU res = ::Menu_AddMainMenuItem(pmi);
lua_pushlightuserdata(L, res);
return 1;
@@ -18,15 +54,19 @@ static int lua_AddMainMenuItem(lua_State *L) static int lua_AddContactMenuItem(lua_State *L)
{
- CLISTMENUITEM mi = { sizeof(mi) };
- mi.pszName = LPGEN((char*)luaL_checkstring(L, 1));
- mi.flags = lua_tointeger(L, 2);
- mi.position = lua_tointeger(L, 3);
- mi.icolibItem = (HANDLE)lua_touserdata(L, 4);
- mi.pszService = (char*)lua_tostring(L, 5);
- mi.hParentMenu = (HGENMENU)lua_touserdata(L, 6);
-
- HGENMENU res = ::Menu_AddContactMenuItem(&mi);
+ if (lua_type(L, 1) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ lua_settop(L, 1);
+
+ mir_ptr<CLISTMENUITEM> pmi(MakeMenuItem(L));
+
+ lua_pop(L, 1);
+
+ HGENMENU res = ::Menu_AddContactMenuItem(pmi);
lua_pushlightuserdata(L, res);
return 1;
|