From bf3a7231bf7f977591c80a7dca44035dfbf9c376 Mon Sep 17 00:00:00 2001 From: aunsane Date: Sat, 2 Sep 2017 20:56:39 +0300 Subject: MirLua: return nil if something went wroing in m_clist and m_genmenu --- plugins/MirLua/src/m_clist.cpp | 35 +++++++++++++++++++++++++---------- plugins/MirLua/src/m_genmenu.cpp | 5 +++-- 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'plugins/MirLua') diff --git a/plugins/MirLua/src/m_clist.cpp b/plugins/MirLua/src/m_clist.cpp index 7620ef9e9e..d5d8d76a10 100644 --- a/plugins/MirLua/src/m_clist.cpp +++ b/plugins/MirLua/src/m_clist.cpp @@ -7,18 +7,26 @@ static int clist_AddMainMenuRoot(lua_State *L) HANDLE hIcon = (HANDLE)lua_touserdata(L, 3); HGENMENU res = Menu_CreateRoot(MO_MAIN, ptrW(Utf8DecodeW(name)), position, hIcon); - lua_pushlightuserdata(L, res); + if (res != nullptr) + lua_pushlightuserdata(L, res); + else + lua_pushnil(L); return 1; } static int clist_AddMainMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + CMenuItem mi; MakeMenuItem(L, mi); HGENMENU res = Menu_AddMainMenuItem(&mi); - lua_pushlightuserdata(L, res); + if (res != nullptr) + lua_pushlightuserdata(L, res); + else + lua_pushnil(L); return 1; } @@ -30,36 +38,43 @@ static int clist_AddContactMenuRoot(lua_State *L) HANDLE hIcon = (HANDLE)lua_touserdata(L, 3); HGENMENU res = Menu_CreateRoot(MO_MAIN, ptrW(Utf8DecodeW(name)), position, hIcon); - lua_pushlightuserdata(L, res); + if (res != nullptr) + lua_pushlightuserdata(L, res); + else + lua_pushnil(L); return 1; } static int clist_AddContactMenuItem(lua_State *L) { + luaL_checktype(L, 1, LUA_TTABLE); + CMenuItem mi; MakeMenuItem(L, mi); ptrA szProto(mir_utf8decodeA(lua_tostring(L, 2))); HGENMENU res = Menu_AddContactMenuItem(&mi, szProto); - lua_pushlightuserdata(L, res); + if (res != nullptr) + lua_pushlightuserdata(L, res); + else + lua_pushnil(L); return 1; } static int clist_AddTrayMenuItem(lua_State *L) { - if (!lua_istable(L, 1)) - { - lua_pushlightuserdata(L, 0); - return 1; - } + luaL_checktype(L, 1, LUA_TTABLE); CMenuItem mi; MakeMenuItem(L, mi); HGENMENU res = Menu_AddTrayMenuItem(&mi); - lua_pushlightuserdata(L, res); + if (res != nullptr) + lua_pushlightuserdata(L, res); + else + lua_pushnil(L); return 1; } diff --git a/plugins/MirLua/src/m_genmenu.cpp b/plugins/MirLua/src/m_genmenu.cpp index b4d42521c6..9c549b6022 100644 --- a/plugins/MirLua/src/m_genmenu.cpp +++ b/plugins/MirLua/src/m_genmenu.cpp @@ -50,7 +50,8 @@ static int genmenu_ModifyMenuItem(lua_State *L) flags |= CMIF_UNICODE; INT_PTR res = Menu_ModifyItem(hMenuItem, name, hIcolibItem, flags); - lua_pushinteger(L, res); + lua_pushboolean(L, res == 0); + return 1; } @@ -63,7 +64,7 @@ static int genmenu_ConfigureMenuItem(lua_State *L) INT_PTR value = (INT_PTR)lua_touserdata(L, 3); int res = Menu_ConfigureItem(hMenuItem, option, value); - lua_pushinteger(L, res); + lua_pushboolean(L, res >= 0); return 1; } -- cgit v1.2.3