diff options
-rw-r--r-- | plugins/MirLua/docs/examples/core.lua | 6 | ||||
-rw-r--r-- | plugins/MirLua/docs/examples/menus.lua | 21 | ||||
-rw-r--r-- | plugins/MirLua/docs/examples/popup.lua | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/m_clist.cpp | 139 | ||||
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 3 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_module_loader.cpp | 1 | ||||
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/stdafx.h | 6 | ||||
-rw-r--r-- | plugins/MirLua/src/version.h | 2 |
9 files changed, 172 insertions, 18 deletions
diff --git a/plugins/MirLua/docs/examples/core.lua b/plugins/MirLua/docs/examples/core.lua index 064ab58fad..e18dc0577a 100644 --- a/plugins/MirLua/docs/examples/core.lua +++ b/plugins/MirLua/docs/examples/core.lua @@ -1,7 +1,7 @@ -- core module (m) is included by default --- include m_genmenu module +--- include m_clist module +local clist = require('m_clist') -- include m_icolib module -local genmenu = require('m_genmenu') local icolib = require('m_icolib') -- Add icon for menu items @@ -10,5 +10,5 @@ local hRestartIcon = icolib.AddIcon('restartIcon', 'Restart') -- Subscribe to [[Miranda/System/ModulesLoaded]] event m.OnModulesLoaded(function() -- Add menu item to main menu that allow to restart Miranda NG - genmenu.AddMainMenuItem("Restart", 0, 0, hRestartIcon, "Miranda/System/Restart") + clist.AddMainMenuItem("Restart", 0, 0, hRestartIcon, "Miranda/System/Restart") end) diff --git a/plugins/MirLua/docs/examples/menus.lua b/plugins/MirLua/docs/examples/menus.lua index 8480c2cbaf..52ec8e3173 100644 --- a/plugins/MirLua/docs/examples/menus.lua +++ b/plugins/MirLua/docs/examples/menus.lua @@ -1,3 +1,5 @@ +--- include m_clist module +local clist = require('m_clist') --- include m_genmenu module local genmenu = require('m_genmenu') --- include m_icolib module @@ -21,47 +23,46 @@ local hIcon = icolib.AddIcon('testMenuIcon', 'Lua icon for menus') menuItem.Name = "Main menu item" menuItem.Icon = hIcon menuItem.Service = "Srv/MMI" -genmenu.AddMainMenuItem(menuItem) +clist.AddMainMenuItem(menuItem) --- Add menu item to main menu menuItem.Name = "Tray menu item" menuItem.Service = "Srv/TMI" -genmenu.AddTrayMenuItem(menuItem) +clist.AddTrayMenuItem(menuItem) --- Add menu item to contact menu menuItem.Name = "Contact menu item" menuItem.Service = "Srv/CMI" -genmenu.AddContactMenuItem(menuItem) +clist.AddContactMenuItem(menuItem) --- Create the contact menu item which will be deleted below menuItem.Name = "testRemove" menuItem.Service = "Srv/TestRemove" -local hMenuItem = genmenu.AddContactMenuItem(menuItem) +local hMenuItem = clist.AddContactMenuItem(menuItem) --- Remove menu item from parent menu genmenu.RemoveMenuItem(hMenuItem) --- Add root menu item local CMIF_ROOTHANDLE = 384 -local hRoot = genmenu.AddMainMenuItem({ Name = "Main menu root", Flags = CMIF_ROOTHANDLE }) +local hRoot = clist.AddMainMenuItem({ Name = "Main menu root", Flags = CMIF_ROOTHANDLE }) --- Add child menu item menuItem.Name = "Main menu child wierd" menuItem.Flags = CMIF_ROOTHANDLE menuItem.Service = 'Srv/SMI' menuItem.Parent = hRoot -local hChild = genmenu.AddMainMenuItem(menuItem) +local hChild = clist.AddMainMenuItem(menuItem) --- Modify menu item local CMIM_NAME = tonumber("80000000", 16) genmenu.ModifyMenuItem(hChild, "Main menu child", hIcon, CMIM_NAME) - -local hDisabledMenuItem = genmenu.AddMainMenuItem({ Name = "Disabled main menu item" }) +local hDisabledMenuItem = clist.AddMainMenuItem({ Name = "Disabled main menu item" }) genmenu.EnableMenuItem(hDisabledMenuItem, false) -local hHiddenMenuItem = genmenu.AddMainMenuItem({ Name = "Hidden main menu item" }) +local hHiddenMenuItem = clist.AddMainMenuItem({ Name = "Hidden main menu item" }) genmenu.ShowMenuItem(hHiddenMenuItem, false) -local hCheckedMenuItem = genmenu.AddMainMenuItem({ Name = "Checked main menu item" }) +local hCheckedMenuItem = clist.AddMainMenuItem({ Name = "Checked main menu item" }) genmenu.CheckMenuItem(hCheckedMenuItem, true) diff --git a/plugins/MirLua/docs/examples/popup.lua b/plugins/MirLua/docs/examples/popup.lua index 395f650267..4d48ace8a3 100644 --- a/plugins/MirLua/docs/examples/popup.lua +++ b/plugins/MirLua/docs/examples/popup.lua @@ -1,7 +1,7 @@ --- include m_popup module local popup = require('m_popup') ---- include m_genmenu module -local genmenu = require('m_genmenu') +--- include m_clist module +local clist = require('m_clist') m.CreateServiceFunction('MirLua/ShowPopup', function() local popupData = @@ -15,5 +15,5 @@ m.CreateServiceFunction('MirLua/ShowPopup', function() end) m.OnModulesLoaded(function() - genmenu.AddMainMenuItem({ Name = "Show lua popup", Service = 'MirLua/ShowPopup' }) + clist.AddMainMenuItem({ Name = "Show lua popup", Service = 'MirLua/ShowPopup' }) end) diff --git a/plugins/MirLua/src/m_clist.cpp b/plugins/MirLua/src/m_clist.cpp new file mode 100644 index 0000000000..bc22237776 --- /dev/null +++ b/plugins/MirLua/src/m_clist.cpp @@ -0,0 +1,139 @@ +#include "stdafx.h"
+
+static void MakeMenuItem(lua_State *L, CMenuItem &mi)
+{
+ mi.hLangpack = hScriptsLangpack;
+
+ lua_pushstring(L, "Flags");
+ lua_gettable(L, -2);
+ mi.flags = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ if (!(mi.flags & CMIF_UNICODE))
+ mi.flags |= CMIF_UNICODE;
+
+ lua_pushstring(L, "Name");
+ lua_gettable(L, -2);
+ mi.name.t = mir_utf8decodeT((char*)luaL_checkstring(L, -1));
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Position");
+ lua_gettable(L, -2);
+ mi.position = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Icon");
+ lua_gettable(L, -2);
+ mi.hIcolibItem = (HANDLE)lua_touserdata(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Service");
+ lua_gettable(L, -2);
+ mi.pszService = (char*)lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "Parent");
+ lua_gettable(L, -2);
+ mi.root = (HGENMENU)lua_touserdata(L, -1);
+ lua_pop(L, 1);
+}
+
+static int lua_AddMainMenuItem(lua_State *L)
+{
+ if (lua_type(L, 1) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ CMenuItem mi;
+ MakeMenuItem(L, mi);
+
+ HGENMENU res = ::Menu_AddMainMenuItem(&mi);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static int lua_BuildMainMenu(lua_State *L)
+{
+ HMENU res = ::Menu_BuildMainMenu();
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static int lua_AddContactMenuItem(lua_State *L)
+{
+ if (lua_type(L, 1) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ CMenuItem mi;
+ MakeMenuItem(L, mi);
+
+ ptrA szProto(mir_utf8decode((char*)lua_tostring(L, 2), NULL));
+
+ HGENMENU res = ::Menu_AddContactMenuItem(&mi, szProto);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static int lua_BuildContactMenu(lua_State *L)
+{
+ MCONTACT hContact = lua_tointeger(L, 1);
+
+ HMENU res = ::Menu_BuildContactMenu(hContact);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static int lua_AddTrayMenuItem(lua_State *L)
+{
+ if (lua_type(L, 1) != LUA_TTABLE)
+ {
+ lua_pushlightuserdata(L, 0);
+ return 1;
+ }
+
+ CMenuItem mi;
+ MakeMenuItem(L, mi);
+
+ HGENMENU res = (HGENMENU)::CallService("CList/AddTrayMenuItem", 0, (LPARAM)&mi);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static int lua_BuildTrayMenu(lua_State *L)
+{
+ HMENU res = (HMENU)::CallService(MS_CLIST_MENUBUILDTRAY);
+ lua_pushlightuserdata(L, res);
+
+ return 1;
+}
+
+static luaL_Reg clistApi[] =
+{
+ { "AddMainMenuItem", lua_AddMainMenuItem },
+ { "BuildMainMenu", lua_BuildMainMenu },
+
+ { "AddContactMenuItem", lua_AddContactMenuItem },
+ { "BuildContactMenu", lua_BuildContactMenu },
+
+ { "AddTrayMenuItem", lua_AddTrayMenuItem },
+ { "BuildTrayMenu", lua_BuildTrayMenu },
+
+ { NULL, NULL }
+};
+
+LUAMOD_API int luaopen_m_clist(lua_State *L)
+{
+ luaL_newlib(L, clistApi);
+
+ return 1;
+}
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index 90dffe5f7c..b022c013d6 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -306,6 +306,7 @@ luaL_Reg coreApi[] = { "ReplaceVariables", lua_ReplaceVariables },
{ "NULL", NULL },
+ { "INVALID_HANDLE_VALUE", NULL },
{ NULL, NULL }
};
@@ -315,6 +316,8 @@ LUAMOD_API int luaopen_m(lua_State *L) luaL_newlib(L, coreApi);
lua_pushlightuserdata(L, NULL);
lua_setfield(L, -2, "NULL");
+ lua_pushlightuserdata(L, INVALID_HANDLE_VALUE);
+ lua_setfield(L, -2, "INVALID_HANDLE_VALUE");
lua_setglobal(L, "m");
return 1;
diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index f25b69abde..5be361fce6 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -17,6 +17,7 @@ void CLuaModuleLoader::LoadModules() // load core module
luaopen_m(L);
// regirter delay loading of miranda modules
+ PreloadModule(MLUA_CLIST, luaopen_m_clist);
PreloadModule(MLUA_DATABASE, luaopen_m_database);
PreloadModule(MLUA_ICOLIB, luaopen_m_icolib);
PreloadModule(MLUA_GENMENU, luaopen_m_genmenu);
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index aab6823b85..371b23d95b 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -1,5 +1,11 @@ #include "stdafx.h"
+bool luaM_checkboolean(lua_State *L, int idx)
+{
+ luaL_checktype(L, 2, LUA_TBOOLEAN);
+ return lua_toboolean(L, idx);
+}
+
WPARAM luaM_towparam(lua_State *L, int idx)
{
WPARAM wParam = NULL;
diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 592640b3e6..b540a208be 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -12,8 +12,8 @@ #include <m_options.h>
#include <m_gui.h>
-#include <m_clist.h>
#include <m_genmenu.h>
+#include <m_clist.h>
#include <m_icolib.h>
#include <m_folders.h>
@@ -62,6 +62,9 @@ extern HANDLE g_hCustomFolderPath; #define MLUA_CORE "m"
LUAMOD_API int (luaopen_m)(lua_State *L);
+#define MLUA_CLIST "m_clist"
+LUAMOD_API int (luaopen_m_clist)(lua_State *L);
+
#define MLUA_DATABASE "m_database"
LUAMOD_API int (luaopen_m_database)(lua_State *L);
@@ -83,6 +86,7 @@ LUAMOD_API int (luaopen_m_toptoolbar)(lua_State *L); #define MLUA_VARIABLES "m_variables"
LUAMOD_API int (luaopen_m_variables)(lua_State *L);
+bool luaM_checkboolean(lua_State *L, int idx);
WPARAM luaM_towparam(lua_State *L, int idx);
LPARAM luaM_tolparam(lua_State *L, int idx);
diff --git a/plugins/MirLua/src/version.h b/plugins/MirLua/src/version.h index ce9b61cf05..f2af4804d5 100644 --- a/plugins/MirLua/src/version.h +++ b/plugins/MirLua/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
-#define __RELEASE_NUM 1
+#define __RELEASE_NUM 2
#define __BUILD_NUM 0
#include <stdver.h>
|