diff options
author | aunsane <aunsane@gmail.com> | 2017-09-02 20:56:39 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-09-02 20:56:39 +0300 |
commit | bf3a7231bf7f977591c80a7dca44035dfbf9c376 (patch) | |
tree | 9f7c0748496bc995a73e4474a64d39b20d0c8b95 /plugins/MirLua | |
parent | fbe8725b4f270dbd5981b0ed642fc52da4405cea (diff) |
MirLua: return nil if something went wroing in m_clist and m_genmenu
Diffstat (limited to 'plugins/MirLua')
-rw-r--r-- | plugins/MirLua/src/m_clist.cpp | 35 | ||||
-rw-r--r-- | plugins/MirLua/src/m_genmenu.cpp | 5 |
2 files changed, 28 insertions, 12 deletions
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;
}
|