From 2b962e1ce27336c7ce3a028a8b5f58f8b3a79e78 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 14 Dec 2015 20:37:32 +0000 Subject: MirLua: minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@15863 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirLua/src/m_genmenu.cpp | 23 +++++++----- plugins/MirLua/src/m_icolib.cpp | 8 +---- plugins/MirLua/src/m_sound.cpp | 60 ------------------------------- plugins/MirLua/src/m_sounds.cpp | 60 +++++++++++++++++++++++++++++++ plugins/MirLua/src/m_windows.cpp | 14 +++++++- plugins/MirLua/src/mlua_module_loader.cpp | 2 +- plugins/MirLua/src/stdafx.h | 4 +-- 7 files changed, 91 insertions(+), 80 deletions(-) delete mode 100644 plugins/MirLua/src/m_sound.cpp create mode 100644 plugins/MirLua/src/m_sounds.cpp (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp index 64ff383ac6..8bad0c23c9 100644 --- a/plugins/MirLua/src/m_genmenu.cpp +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -47,7 +47,7 @@ void MakeMenuItem(lua_State *L, CMenuItem &mi) static int lua_CreateRoot(lua_State *L) { - int hMenuObject = lua_tointeger(L, 1); + int hMenuObject = luaL_checkinteger(L, 1); const char *name = luaL_checkstring(L, 2); int position = lua_tointeger(L, 3); HANDLE hIcon = (HANDLE)lua_touserdata(L, 4); @@ -60,7 +60,7 @@ static int lua_CreateRoot(lua_State *L) static int lua_AddMenuItem(lua_State *L) { - int hMenuObject = lua_tointeger(L, 1); + int hMenuObject = luaL_checkinteger(L, 1); if (lua_type(L, 2) != LUA_TTABLE) { @@ -71,7 +71,7 @@ static int lua_AddMenuItem(lua_State *L) CMenuItem mi; MakeMenuItem(L, mi); - HGENMENU res = ::Menu_AddItem(hMenuObject, &mi, NULL); + HGENMENU res = Menu_AddItem(hMenuObject, &mi, NULL); lua_pushlightuserdata(L, res); return 1; @@ -79,6 +79,7 @@ static int lua_AddMenuItem(lua_State *L) static int lua_ModifyMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); ptrT name(mir_utf8decodeT(lua_tostring(L, 2))); HANDLE hIcolibItem = lua_touserdata(L, 3); @@ -87,47 +88,51 @@ static int lua_ModifyMenuItem(lua_State *L) if (!(flags & CMIF_UNICODE)) flags |= CMIF_UNICODE; - INT_PTR res = ::Menu_ModifyItem(hMenuItem, name, hIcolibItem, flags); + INT_PTR res = Menu_ModifyItem(hMenuItem, name, hIcolibItem, flags); lua_pushinteger(L, res); return 1; } static int lua_ShowMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); bool isShow = luaM_toboolean(L, 2); - ::Menu_ShowItem(hMenuItem, isShow); + Menu_ShowItem(hMenuItem, isShow); return 0; } static int lua_EnableMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); bool isEnable = luaM_toboolean(L, 2); - ::Menu_EnableItem(hMenuItem, isEnable); + Menu_EnableItem(hMenuItem, isEnable); return 0; } static int lua_CheckMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); bool isChecked = luaM_toboolean(L, 2); - ::Menu_SetChecked(hMenuItem, isChecked); + Menu_SetChecked(hMenuItem, isChecked); return 0; } static int lua_RemoveMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); HGENMENU hMenuItem = (HGENMENU)lua_touserdata(L, 1); - INT_PTR res = ::Menu_RemoveItem(hMenuItem); - lua_pushinteger(L, res); + INT_PTR res = Menu_RemoveItem(hMenuItem); + lua_pushboolean(L, res == 0); return 1; } diff --git a/plugins/MirLua/src/m_icolib.cpp b/plugins/MirLua/src/m_icolib.cpp index 5b2a5b23a3..733fab90e0 100644 --- a/plugins/MirLua/src/m_icolib.cpp +++ b/plugins/MirLua/src/m_icolib.cpp @@ -35,18 +35,12 @@ static int lua_GetIcon(lua_State *L) static int lua_RemoveIcon(lua_State *L) { - INT_PTR res = 0; - if (lua_isuserdata(L, 1)) ::IcoLib_RemoveIconByHandle(lua_touserdata(L, 1)); else if (lua_isstring(L, 1)) ::IcoLib_RemoveIcon(luaL_checkstring(L, 1)); - else - res = 1; - lua_pushinteger(L, res); - - return 1; + return 0; } static luaL_Reg icolibApi[] = diff --git a/plugins/MirLua/src/m_sound.cpp b/plugins/MirLua/src/m_sound.cpp deleted file mode 100644 index 3411f72971..0000000000 --- a/plugins/MirLua/src/m_sound.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "stdafx.h" - -static int lua_Add(lua_State *L) -{ - ptrA name(mir_utf8decodeA(luaL_checkstring(L, 1))); - ptrT description(mir_utf8decodeT(luaL_checkstring(L, 2))); - ptrT section(mir_utf8decodeT(luaL_optstring(L, 3, MODULE))); - - TCHAR filePath[MAX_PATH]; - GetModuleFileName(g_hInstance, filePath, _countof(filePath)); - - SKINSOUNDDESCEX ssd = { sizeof(SKINSOUNDDESCEX) }; - ssd.pszName = name; - ssd.dwFlags = SSDF_TCHAR; - ssd.ptszDescription = description; - ssd.ptszSection = section; - ssd.ptszDefaultFile = filePath; - - INT_PTR res = ::CallService("Skin/Sounds/AddNew", hLangpack, (LPARAM)&ssd); - lua_pushnumber(L, res); - - return 1; -} - -static int lua_Play(lua_State *L) -{ - const char *name = luaL_checkstring(L, 1); - - INT_PTR res = SkinPlaySound(name); - lua_pushnumber(L, res); - - return 1; -} - -static int lua_PlayFile(lua_State *L) -{ - const char *path = luaL_checkstring(L, 1); - - INT_PTR res = SkinPlaySoundFile(ptrT(mir_utf8decodeT(path))); - lua_pushnumber(L, res); - - return 1; -} - -static luaL_Reg soundApi[] = -{ - { "Add", lua_Add }, - { "Play", lua_Play }, - - { "PlayFile", lua_PlayFile }, - - { NULL, NULL } -}; - -LUAMOD_API int luaopen_m_sound(lua_State *L) -{ - luaL_newlib(L, soundApi); - - return 1; -} diff --git a/plugins/MirLua/src/m_sounds.cpp b/plugins/MirLua/src/m_sounds.cpp new file mode 100644 index 0000000000..8630c53093 --- /dev/null +++ b/plugins/MirLua/src/m_sounds.cpp @@ -0,0 +1,60 @@ +#include "stdafx.h" + +static int lua_AddSound(lua_State *L) +{ + ptrA name(mir_utf8decodeA(luaL_checkstring(L, 1))); + ptrT description(mir_utf8decodeT(luaL_checkstring(L, 2))); + ptrT section(mir_utf8decodeT(luaL_optstring(L, 3, MODULE))); + + TCHAR filePath[MAX_PATH]; + GetModuleFileName(g_hInstance, filePath, _countof(filePath)); + + SKINSOUNDDESCEX ssd = { sizeof(SKINSOUNDDESCEX) }; + ssd.pszName = name; + ssd.dwFlags = SSDF_TCHAR; + ssd.ptszDescription = description; + ssd.ptszSection = section; + ssd.ptszDefaultFile = filePath; + + INT_PTR res = ::CallService("Skin/Sounds/AddNew", hLangpack, (LPARAM)&ssd); + lua_pushnumber(L, res); + + return 1; +} + +static int lua_PlaySound(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + + INT_PTR res = SkinPlaySound(name); + lua_pushnumber(L, res); + + return 1; +} + +static int lua_PlayFile(lua_State *L) +{ + const char *path = luaL_checkstring(L, 1); + + INT_PTR res = SkinPlaySoundFile(ptrT(mir_utf8decodeT(path))); + lua_pushnumber(L, res); + + return 1; +} + +static luaL_Reg soundApi[] = +{ + { "AddSound", lua_AddSound }, + { "PlaySound", lua_PlaySound }, + + { "PlayFile", lua_PlayFile }, + + { NULL, NULL } +}; + +LUAMOD_API int luaopen_m_sounds(lua_State *L) +{ + luaL_newlib(L, soundApi); + + return 1; +} diff --git a/plugins/MirLua/src/m_windows.cpp b/plugins/MirLua/src/m_windows.cpp index b78f9f7278..160f632974 100644 --- a/plugins/MirLua/src/m_windows.cpp +++ b/plugins/MirLua/src/m_windows.cpp @@ -147,7 +147,7 @@ static int lua_FindIterator(lua_State *L) static int lua_Find(lua_State *L) { - TCHAR* path = mir_utf8decodeT(luaL_checkstring(L, 1)); + TCHAR *path = mir_utf8decodeT(luaL_checkstring(L, 1)); lua_pushlightuserdata(L, NULL); lua_pushlightuserdata(L, path); @@ -156,6 +156,16 @@ static int lua_Find(lua_State *L) return 1; } +static int lua_GetKeyState(lua_State *L) +{ + int vKey = luaL_checkinteger(L, 1); + + int res = GetKeyState(vKey); + lua_pushinteger(L, res); + + return 1; +} + static int lua_GetIniValue(lua_State *L) { ptrT path(mir_utf8decodeT(luaL_checkstring(L, 1))); @@ -358,6 +368,8 @@ static luaL_Reg winApi[] = { "Find", lua_Find }, + { "GetKeyState", lua_GetKeyState }, + { "GetIniValue", lua_GetIniValue }, { "SetIniValue", lua_SetIniValue }, { "DeleteIniValue", lua_DeleteIniValue }, diff --git a/plugins/MirLua/src/mlua_module_loader.cpp b/plugins/MirLua/src/mlua_module_loader.cpp index e6fc4e2251..a4cce4f418 100644 --- a/plugins/MirLua/src/mlua_module_loader.cpp +++ b/plugins/MirLua/src/mlua_module_loader.cpp @@ -26,7 +26,7 @@ void CLuaModuleLoader::LoadModules() PreloadModule(MLUA_POPUP, luaopen_m_popup); PreloadModule(MLUA_PROTOCOLS, luaopen_m_protocols); PreloadModule(MLUA_SCHEDULE, luaopen_m_schedule); - PreloadModule(MLUA_SOUND, luaopen_m_sound); + PreloadModule(MLUA_SOUNDS, luaopen_m_sounds); PreloadModule(MLUA_TOPTOOLBAR, luaopen_m_toptoolbar); PreloadModule(MLUA_VARIABLES, luaopen_m_variables); PreloadModule(MLUA_WINDOWS, luaopen_m_windows); diff --git a/plugins/MirLua/src/stdafx.h b/plugins/MirLua/src/stdafx.h index 3eb5c82241..2192f19872 100644 --- a/plugins/MirLua/src/stdafx.h +++ b/plugins/MirLua/src/stdafx.h @@ -99,8 +99,8 @@ LUAMOD_API int (luaopen_m_popup)(lua_State *L); #include "m_schedule.h" -#define MLUA_SOUND "m_sound" -LUAMOD_API int (luaopen_m_sound)(lua_State *L); +#define MLUA_SOUNDS "m_sounds" +LUAMOD_API int (luaopen_m_sounds)(lua_State *L); #include "m_toptoolbar.h" -- cgit v1.2.3