From 031b81f8764de5e566490248dbc4bb466c0b03e9 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev <aunsane@gmail.com> Date: Wed, 10 Jun 2015 21:00:17 +0000 Subject: MirLua: - added OnModulesLoaded handler - added OnPreShutdown handler - renamed existing modules - changed modules loading - chaged examples git-svn-id: http://svn.miranda-ng.org/main/trunk@14107 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/docs/examples/icons.lua | 12 +- plugins/MirLua/docs/examples/menus.lua | 14 +-- plugins/MirLua/src/m_core.cpp | 207 +++++++++++++++++++++++++++++++++ plugins/MirLua/src/m_genmenu.cpp | 57 +++++++++ plugins/MirLua/src/m_icolib.cpp | 70 +++++++++++ plugins/MirLua/src/mlua.cpp | 8 +- plugins/MirLua/src/mlua.h | 2 +- plugins/MirLua/src/mlua_core.cpp | 159 ------------------------- plugins/MirLua/src/mlua_icons.cpp | 77 ------------ plugins/MirLua/src/mlua_menus.cpp | 64 ---------- plugins/MirLua/src/stdafx.h | 8 +- 11 files changed, 356 insertions(+), 322 deletions(-) create mode 100644 plugins/MirLua/src/m_core.cpp create mode 100644 plugins/MirLua/src/m_genmenu.cpp create mode 100644 plugins/MirLua/src/m_icolib.cpp delete mode 100644 plugins/MirLua/src/mlua_core.cpp delete mode 100644 plugins/MirLua/src/mlua_icons.cpp delete mode 100644 plugins/MirLua/src/mlua_menus.cpp (limited to 'plugins') diff --git a/plugins/MirLua/docs/examples/icons.lua b/plugins/MirLua/docs/examples/icons.lua index 7b9f6dca6c..4d54cb8e8b 100644 --- a/plugins/MirLua/docs/examples/icons.lua +++ b/plugins/MirLua/docs/examples/icons.lua @@ -1,22 +1,22 @@ ---- include m_icons module -require('m_icons') +--- include m_icolib module +local icolib = require('m_icolib') --- Add icon to icoLib -- @param name The name of icon -- @param description The description of icon -- @param section The section in witch icon will be stored (default 'MirLua') -- @return handle of icon -M.Icons.AddIcon('testIcon', 'Lua icon', 'MirLua') +icolib.AddIcon('testIcon', 'Lua icon', 'MirLua') --- Create the icon which will be deleted below -M.Icons.AddIcon('testRemoved', 'Lua temporary icon') +icolib.AddIcon('testRemoved', 'Lua temporary icon') --- Get icon by name -- @param name The name of icon -- @return handle of icon -local hIcon = M.Icons.GetIcon('testRemoved') +local hIcon = icolib.GetIcon('testRemoved') --- Remove icon from iconLib -- @param handle The handle of icon (or name) -- @return 0 on success -M.Icons.RemoveIcon('testRemoved') +icolib.RemoveIcon('testRemoved') diff --git a/plugins/MirLua/docs/examples/menus.lua b/plugins/MirLua/docs/examples/menus.lua index b2a3f222d2..90ace6f6d9 100644 --- a/plugins/MirLua/docs/examples/menus.lua +++ b/plugins/MirLua/docs/examples/menus.lua @@ -1,9 +1,9 @@ --- include m_menus module -require('m_menus') -require('m_icons') +local genmenu = require('m_genmenu') +local icolib = require('m_icolib') --- Add icon for menu items -local hIcon = M.Icons.AddIcon('testMenuIcon', 'Lua icon for menus') +local hIcon = icolib.AddIcon('testMenuIcon', 'Lua icon for menus') --- Add menu item to main menu -- @param name The name of menu item @@ -12,7 +12,7 @@ local hIcon = M.Icons.AddIcon('testMenuIcon', 'Lua icon for menus') -- @param icon The handle of icon of menu item (default NULL) -- @param service The name of service which will be called (default '') -- @return handle of menu item -M.Menus.AddMainMenuItem('Main menu item', 0, 0, hIcon, 'Srv/MMI') +genmenu.AddMainMenuItem('Main menu item', 0, 0, hIcon, 'Srv/MMI') --- Add menu item to contact menu -- @param name The name of menu item @@ -21,12 +21,12 @@ M.Menus.AddMainMenuItem('Main menu item', 0, 0, hIcon, 'Srv/MMI') -- @param icon The handle of icon of menu item (default NULL) -- @param service The name of service which will be called (default '') -- @return handle of menu item -M.Menus.AddContactMenuItem('Contact menu item', 0, 0, hIcon, 'Srv/CMI') +genmenu.AddContactMenuItem('Contact menu item', 0, 0, hIcon, 'Srv/CMI') --- Create the contact menu item which will be deleted below -local hMenuItem = M.Menus.AddContactMenuItem('testRemove', 0, 0, 0, 'Srv/TestRemove') +local hMenuItem = genmenu.AddContactMenuItem('testRemove', 0, 0, 0, 'Srv/TestRemove') --- Remove menu item from parent menu -- @param handle The handle of menu item -- @return 0 on success -M.Menus.RemoveMenuItem(hMenuItem) +genmenu.RemoveMenuItem(hMenuItem) diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp new file mode 100644 index 0000000000..21cd25ce80 --- /dev/null +++ b/plugins/MirLua/src/m_core.cpp @@ -0,0 +1,207 @@ +#include "stdafx.h" + +static int lua_CreateHookableEvent(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + + HANDLE res = ::CreateHookableEvent(name); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_DestroyHookableEvent(lua_State *L) +{ + HANDLE hEvent = (HANDLE)lua_touserdata(L, 1); + + int res = ::DestroyHookableEvent(hEvent); + lua_pushinteger(L, res); + + return 1; +} + +static int lua_NotifyEventHooks(lua_State *L) +{ + HANDLE hEvent = (HANDLE)lua_touserdata(L, 1); + WPARAM wParam = (WPARAM)luaL_checkinteger(L, 2); + LPARAM lParam = (LPARAM)luaL_checkinteger(L, 3); + + int res = ::NotifyEventHooks(hEvent, wParam, lParam); + lua_pushinteger(L, res); + + return 1; +} + +static 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_pushnumber(L, wParam); + lua_pushnumber(L, lParam); + if(lua_pcall(L, 2, 1, 0)) + printf("%s\n", lua_tostring(L, -1)); + + int res = (int)lua_tointeger(L, 1); + + //luaL_unref(L, LUA_REGISTRYINDEX, ref); + + return res; +} + +static int lua_HookEvent(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + + if (!lua_isfunction(L, 2)) + { + lua_pushlightuserdata(L, NULL); + return 1; + } + + lua_pushvalue(L, 2); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + + HANDLE res = ::HookEventObjParam(name, HookEventObjParam, L, ref); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_UnhookEvent(lua_State *L) +{ + HANDLE hEvent = (HANDLE)lua_touserdata(L, 1); + + int res = ::UnhookEvent(hEvent); + lua_pushinteger(L, res); + + return 1; +} + +static int lua_OnModulesLoaded(lua_State *L) +{ + if (!lua_isfunction(L, 1)) + { + lua_pushlightuserdata(L, NULL); + return 1; + } + + lua_pushvalue(L, 1); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + + HANDLE res = ::HookEventObjParam(ME_SYSTEM_MODULESLOADED, HookEventObjParam, L, ref); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_OnPreShutdown(lua_State *L) +{ + if (!lua_isfunction(L, 1)) + { + lua_pushlightuserdata(L, NULL); + return 1; + } + + lua_pushvalue(L, 1); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + + HANDLE res = ::HookEventObjParam(ME_SYSTEM_PRESHUTDOWN, HookEventObjParam, L, ref); + lua_pushlightuserdata(L, res); + + return 1; +} + +static INT_PTR ServiceFunctionObjParam(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); + if (lua_pcall(L, 2, 1, 0)) + printf("%s\n", lua_tostring(L, -1)); + + INT_PTR res = (INT_PTR)lua_tointeger(L, 1); + + //luaL_unref(L, LUA_REGISTRYINDEX, ref); + + return res; +} + +static int lua_CreateServiceFunction(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + + if (!lua_isfunction(L, 2)) + { + lua_pushlightuserdata(L, NULL); + return 1; + } + + lua_pushvalue(L, 2); + int ref = luaL_ref(L, LUA_REGISTRYINDEX); + + HANDLE res = ::CreateServiceFunctionObjParam(name, ServiceFunctionObjParam, L, ref); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_DestroyServiceFunction(lua_State *L) +{ + HANDLE hService = (HANDLE)lua_touserdata(L, 1); + + int res = ::DestroyServiceFunction(hService); + lua_pushinteger(L, res); + + return 1; +} + +static int lua_ServiceExists(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + + int res = ::ServiceExists(name); + lua_pushboolean(L, res); + + return 1; +} + +static int lua_CallService(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + + WPARAM wParam = (WPARAM)luaL_checkinteger(L, 2); + LPARAM lParam = (LPARAM)luaL_checkinteger(L, 3); + + INT_PTR res = ::CallService(name, wParam, lParam); + lua_pushinteger(L, res); + + return 1; +} + +luaL_Reg CMLua::coreLib[] = +{ + { "CreateHookableEvent", lua_CreateHookableEvent }, + { "DestroyHookableEvent", lua_DestroyHookableEvent }, + + { "NotifyEventHooks", lua_NotifyEventHooks }, + + { "HookEvent", lua_HookEvent }, + { "UnhookEvent", lua_UnhookEvent }, + { "OnModulesLoaded", lua_OnModulesLoaded }, + { "OnPreShutdown", lua_OnPreShutdown }, + + { "CreateServiceFunction", lua_CreateServiceFunction }, + { "DestroyServiceFunction", lua_DestroyServiceFunction }, + + { "ServiceExists", lua_ServiceExists }, + { "CallService", lua_CallService }, + + { NULL, NULL } +}; diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp new file mode 100644 index 0000000000..5a185f64bd --- /dev/null +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -0,0 +1,57 @@ +#include "stdafx.h" + +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); + + HGENMENU res = ::Menu_AddMainMenuItem(&mi); + lua_pushlightuserdata(L, res); + + return 1; +} + +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); + + HGENMENU res = ::Menu_AddContactMenuItem(&mi); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_RemoveMenuItem(lua_State *L) +{ + HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); + + INT_PTR res = ::CallService(MO_REMOVEMENUITEM, (WPARAM)hMenuItem, 0); + lua_pushinteger(L, res); + + return 1; +} + +static luaL_Reg genmenuApi[] = +{ + { "AddMainMenuItem", lua_AddMainMenuItem }, + { "AddContactMenuItem", lua_AddContactMenuItem }, + { "RemoveMenuItem", lua_RemoveMenuItem }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_genmenu(lua_State *L) +{ + luaL_newlib(L, genmenuApi); + + return 1; +} diff --git a/plugins/MirLua/src/m_icolib.cpp b/plugins/MirLua/src/m_icolib.cpp new file mode 100644 index 0000000000..cc8808aa0e --- /dev/null +++ b/plugins/MirLua/src/m_icolib.cpp @@ -0,0 +1,70 @@ +#include "stdafx.h" + +static int lua_AddIcon(lua_State *L) +{ + TCHAR filePath[MAX_PATH]; + GetModuleFileName(g_hInstance, filePath, SIZEOF(filePath)); + + char iconName[MAX_PATH]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, luaL_checkstring(L, 1)); + + SKINICONDESC si = { 0 }; + si.flags = SIDF_PATH_TCHAR; + si.pszName = iconName; + si.description.a = (char*)lua_tostring(L, 2); + si.section.a = lua_isnone(L, 3) ? "MirLua" : (char*)lua_tostring(L, 3); + si.defaultFile.t = filePath; + si.iDefaultIndex = -IDI_ICON; + + HANDLE res = ::Skin_AddIcon(&si); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_GetIcon(lua_State *L) +{ + char iconName[MAX_PATH]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, luaL_checkstring(L, 1)); + + HANDLE res = ::Skin_GetIconHandle(iconName); + lua_pushlightuserdata(L, res); + + return 1; +} + +static int lua_RemoveIcon(lua_State *L) +{ + INT_PTR res = 0; + + if (lua_isuserdata(L, 1)) + res = ::CallService(MS_SKIN2_REMOVEICON, (WPARAM)lua_touserdata(L, 1), 0); + else if (lua_isstring(L, 1)) + { + char iconName[MAX_PATH]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, lua_tostring(L, 1)); + res = ::CallService(MS_SKIN2_REMOVEICON, 0, (LPARAM)iconName); + } + else + res = 1; + + lua_pushinteger(L, res); + + return 1; +} + +static luaL_Reg icolibApi[] = +{ + { "AddIcon", lua_AddIcon }, + { "GetIcon", lua_GetIcon }, + { "RemoveIcon", lua_RemoveIcon }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_icolib(lua_State *L) +{ + luaL_newlib(L, icolibApi); + + return 1; +} diff --git a/plugins/MirLua/src/mlua.cpp b/plugins/MirLua/src/mlua.cpp index b6d3895940..c600ad058e 100644 --- a/plugins/MirLua/src/mlua.cpp +++ b/plugins/MirLua/src/mlua.cpp @@ -13,10 +13,10 @@ CMLua::CMLua() lua_pop(L, 1); luaL_newlib(L, coreLib); - lua_setglobal(L, "M"); + lua_setglobal(L, "m"); - Preload(M_ICONSLIBNAME, luaopen_m_icons); - Preload(M_MENUSLIBNAME, luaopen_m_menus); + Preload(MLUA_ICOLIB, luaopen_m_icolib); + Preload(MLUA_GENMENU, luaopen_m_genmenu); } CMLua::~CMLua() @@ -37,7 +37,7 @@ void CMLua::AddPath(const char *path) void CMLua::Load(const char *path) { - if (luaL_dofile(L, path)); + if (luaL_dofile(L, path)) printf("%s\n", lua_tostring(L, -1)); } diff --git a/plugins/MirLua/src/mlua.h b/plugins/MirLua/src/mlua.h index 54f6c4d987..8abc839bd0 100644 --- a/plugins/MirLua/src/mlua.h +++ b/plugins/MirLua/src/mlua.h @@ -5,7 +5,7 @@ class CMLua { private: lua_State *L; - static luaL_Reg coreLib[10]; + static luaL_Reg coreLib[12]; void Preload(const char *name, lua_CFunction func); diff --git a/plugins/MirLua/src/mlua_core.cpp b/plugins/MirLua/src/mlua_core.cpp deleted file mode 100644 index 7e26e8b354..0000000000 --- a/plugins/MirLua/src/mlua_core.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "stdafx.h" - -static int lua_CreateHookableEvent(lua_State *L) -{ - const char *name = luaL_checkstring(L, 1); - - HANDLE res = ::CreateHookableEvent(name); - lua_pushlightuserdata(L, res); - - return 1; -} - -static int lua_DestroyHookableEvent(lua_State *L) -{ - HANDLE hEvent = (HANDLE)lua_touserdata(L, 1); - - int res = ::DestroyHookableEvent(hEvent); - lua_pushinteger(L, res); - - return 1; -} - -static int lua_NotifyEventHooks(lua_State *L) -{ - HANDLE hEvent = (HANDLE)lua_touserdata(L, 1); - WPARAM wParam = (WPARAM)luaL_checkinteger(L, 2); - LPARAM lParam = (LPARAM)luaL_checkinteger(L, 3); - - int res = ::NotifyEventHooks(hEvent, wParam, lParam); - lua_pushinteger(L, res); - - return 1; -} - -static 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_pushnumber(L, wParam); - lua_pushnumber(L, lParam); - if(lua_pcall(L, 2, 1, 0)) - printf("%s\n", lua_tostring(L, -1)); - - int res = (int)lua_tointeger(L, 1); - - //luaL_unref(L, LUA_REGISTRYINDEX, ref); - - return res; -} - -static int lua_HookEvent(lua_State *L) -{ - const char *name = luaL_checkstring(L, 1); - - lua_pushvalue(L, 2); - int ref = luaL_ref(L, LUA_REGISTRYINDEX); - - HANDLE res = ::HookEventObjParam(name, HookEventObjParam, L, ref); - lua_pushlightuserdata(L, res); - - return 1; -} - -static int lua_UnhookEvent(lua_State *L) -{ - HANDLE hEvent = (HANDLE)lua_touserdata(L, 1); - - int res = ::UnhookEvent(hEvent); - lua_pushinteger(L, res); - - return 1; -} - -static INT_PTR ServiceFunctionObjParam(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); - if (lua_pcall(L, 2, 1, 0)) - printf("%s\n", lua_tostring(L, -1)); - - INT_PTR res = (INT_PTR)lua_tointeger(L, 1); - - //luaL_unref(L, LUA_REGISTRYINDEX, ref); - - return res; -} - -static int lua_CreateServiceFunction(lua_State *L) -{ - const char *name = luaL_checkstring(L, 1); - - lua_pushvalue(L, 2); - int ref = luaL_ref(L, LUA_REGISTRYINDEX); - - HANDLE res = ::CreateServiceFunctionObjParam(name, ServiceFunctionObjParam, L, ref); - lua_pushlightuserdata(L, res); - - return 1; -} - -static int lua_DestroyServiceFunction(lua_State *L) -{ - HANDLE hService = (HANDLE)lua_touserdata(L, 1); - - int res = ::DestroyServiceFunction(hService); - lua_pushinteger(L, res); - - return 1; -} - -static int lua_ServiceExists(lua_State *L) -{ - const char *name = luaL_checkstring(L, 1); - - int res = ::ServiceExists(name); - lua_pushboolean(L, res); - - return 1; -} - -static int lua_CallService(lua_State *L) -{ - const char *name = luaL_checkstring(L, 1); - - WPARAM wParam = (WPARAM)luaL_checkinteger(L, 2); - LPARAM lParam = (LPARAM)luaL_checkinteger(L, 3); - - INT_PTR res = ::CallService(name, wParam, lParam); - lua_pushinteger(L, res); - - return 1; -} - -luaL_Reg CMLua::coreLib[] = -{ - { "CreateHookableEvent", lua_CreateHookableEvent }, - { "DestroyHookableEvent", lua_DestroyHookableEvent }, - - { "NotifyEventHooks", lua_NotifyEventHooks }, - - { "HookEvent", lua_HookEvent }, - { "UnhookEvent", lua_UnhookEvent }, - - { "CreateServiceFunction", lua_CreateServiceFunction }, - { "DestroyServiceFunction", lua_DestroyServiceFunction }, - - { "ServiceExists", lua_ServiceExists }, - { "CallService", lua_CallService }, - - { NULL, NULL } -}; diff --git a/plugins/MirLua/src/mlua_icons.cpp b/plugins/MirLua/src/mlua_icons.cpp deleted file mode 100644 index 5c53694f15..0000000000 --- a/plugins/MirLua/src/mlua_icons.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "stdafx.h" - -static int lua_AddIcon(lua_State *L) -{ - TCHAR filePath[MAX_PATH]; - GetModuleFileName(g_hInstance, filePath, SIZEOF(filePath)); - - char iconName[MAX_PATH]; - mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, luaL_checkstring(L, 1)); - - SKINICONDESC si = { 0 }; - si.flags = SIDF_PATH_TCHAR; - si.pszName = iconName; - si.description.a = (char*)lua_tostring(L, 2); - si.section.a = lua_isnone(L, 3) ? "MirLua" : (char*)lua_tostring(L, 3); - si.defaultFile.t = filePath; - si.iDefaultIndex = -IDI_ICON; - - HANDLE res = ::Skin_AddIcon(&si); - lua_pushlightuserdata(L, res); - - return 1; -} - -static int lua_GetIcon(lua_State *L) -{ - char iconName[MAX_PATH]; - mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, luaL_checkstring(L, 1)); - - HANDLE res = ::Skin_GetIconHandle(iconName); - lua_pushlightuserdata(L, res); - - return 1; -} - -static int lua_RemoveIcon(lua_State *L) -{ - INT_PTR res = 0; - - if (lua_isuserdata(L, 1)) - res = ::CallService(MS_SKIN2_REMOVEICON, (WPARAM)lua_touserdata(L, 1), 0); - else if (lua_isstring(L, 1)) - { - char iconName[MAX_PATH]; - mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, lua_tostring(L, 1)); - res = ::CallService(MS_SKIN2_REMOVEICON, 0, (LPARAM)iconName); - } - else - res = 1; - - lua_pushinteger(L, res); - - return 1; -} - -static luaL_Reg iconsLib[] = -{ - { "AddIcon", lua_AddIcon }, - { "GetIcon", lua_GetIcon }, - { "RemoveIcon", lua_RemoveIcon }, - - { NULL, NULL } -}; - -int luaopen_m_icons(lua_State *L) -{ - lua_getglobal(L, "M"); - luaL_checktype(L, -1, LUA_TTABLE); - - lua_newtable(L); - luaL_setfuncs(L, iconsLib, 0); - lua_setfield(L, -2, "Icons"); - - lua_pop(L, 1); - - return 1; -} diff --git a/plugins/MirLua/src/mlua_menus.cpp b/plugins/MirLua/src/mlua_menus.cpp deleted file mode 100644 index e59bc33a0f..0000000000 --- a/plugins/MirLua/src/mlua_menus.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "stdafx.h" - -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); - - HGENMENU res = ::Menu_AddMainMenuItem(&mi); - lua_pushlightuserdata(L, res); - - return 1; -} - -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); - - HGENMENU res = ::Menu_AddContactMenuItem(&mi); - lua_pushlightuserdata(L, res); - - return 1; -} - -static int lua_RemoveMenuItem(lua_State *L) -{ - HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); - - INT_PTR res = ::CallService(MO_REMOVEMENUITEM, (WPARAM)hMenuItem, 0); - lua_pushinteger(L, res); - - return 1; -} - -static luaL_Reg menusLib[] = -{ - { "AddMainMenuItem", lua_AddMainMenuItem }, - { "AddContactMenuItem", lua_AddContactMenuItem }, - { "RemoveMenuItem", lua_RemoveMenuItem }, - - { NULL, NULL } -}; - -int luaopen_m_menus(lua_State *L) -{ - lua_getglobal(L, "M"); - luaL_checktype(L, -1, LUA_TTABLE); - - lua_newtable(L); - luaL_setfuncs(L, menusLib, 0); - lua_setfield(L, -2, "Menus"); - - lua_pop(L, 1); - - return 1; -} diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index f2e484e579..6d206f7644 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -38,10 +38,10 @@ extern HINSTANCE g_hInstance; #define CUSTOM_SCRIPTS_PATHT MIRANDA_USERDATA "\\Scripts" #endif -#define M_ICONSLIBNAME "m_icons" -int luaopen_m_icons(lua_State *L); +#define MLUA_ICOLIB "m_icolib" +LUAMOD_API int (luaopen_m_icolib)(lua_State *L); -#define M_MENUSLIBNAME "m_menus" -int luaopen_m_menus(lua_State *L); +#define MLUA_GENMENU "m_genmenu" +LUAMOD_API int (luaopen_m_genmenu)(lua_State *L); #endif //_COMMON_H_ -- cgit v1.2.3