summaryrefslogtreecommitdiff
path: root/plugins/MirLua/src
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2015-06-30 15:31:44 +0000
committerAlexander Lantsev <aunsane@gmail.com>2015-06-30 15:31:44 +0000
commit5dac5be47f2d9af8cbceead6511ff4c0fc40bab5 (patch)
treee7835f34984466b1382e75c8eebc656f4e9cfb4f /plugins/MirLua/src
parentf65741787bee7c5d143d733efb32b7ec3452edc6 (diff)
MirLua: !api break
- separated m_clist and m_genmenu modules - moved AddMainMenuItem, AddContactMenuItem, AddTrayMenuItem to m_clist - added BuildMainMenu, BuildContactMenu and BuildTrayMenu to m_clist - updated examples - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@14458 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirLua/src')
-rw-r--r--plugins/MirLua/src/m_clist.cpp139
-rw-r--r--plugins/MirLua/src/m_core.cpp3
-rw-r--r--plugins/MirLua/src/mlua_module_loader.cpp1
-rw-r--r--plugins/MirLua/src/mlua_utils.cpp6
-rw-r--r--plugins/MirLua/src/stdafx.h6
-rw-r--r--plugins/MirLua/src/version.h2
6 files changed, 155 insertions, 2 deletions
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>