diff options
author | aunsane <aunsane@gmail.com> | 2017-09-02 22:08:32 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-09-02 22:08:57 +0300 |
commit | bc4da963e5ebc651d1d7839a4da39ba59dfa4ea0 (patch) | |
tree | 9f3431f4ebf9688e76c99a4b357e120bfc0de284 /plugins | |
parent | bf3a7231bf7f977591c80a7dca44035dfbf9c376 (diff) |
MirLua: small refactoring
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/MirLua/src/m_core.cpp | 9 | ||||
-rw-r--r-- | plugins/MirLua/src/m_database.cpp | 72 | ||||
-rw-r--r-- | plugins/MirLua/src/m_hotkeys.cpp | 8 |
3 files changed, 36 insertions, 53 deletions
diff --git a/plugins/MirLua/src/m_core.cpp b/plugins/MirLua/src/m_core.cpp index 46d6c50c8b..c58ce9cf1f 100644 --- a/plugins/MirLua/src/m_core.cpp +++ b/plugins/MirLua/src/m_core.cpp @@ -5,14 +5,11 @@ static int core_CreateHookableEvent(lua_State *L) const char *name = luaL_checkstring(L, 1);
HANDLE res = CreateHookableEvent(name);
- if (res == NULL)
- {
+ if (res != nullptr)
+ lua_pushlightuserdata(L, res);
+ else
lua_pushnil(L);
- return 1;
- }
- lua_pushlightuserdata(L, res);
-
return 1;
}
diff --git a/plugins/MirLua/src/m_database.cpp b/plugins/MirLua/src/m_database.cpp index 79a07c898a..9619b36584 100644 --- a/plugins/MirLua/src/m_database.cpp +++ b/plugins/MirLua/src/m_database.cpp @@ -53,54 +53,42 @@ static int db_Contacts(lua_State *L) return 1;
}
+static const char *mods[] =
+{
+ "FirstName",
+ "LastName",
+ "Nick",
+ "CustomNick",
+ "Email",
+ "City",
+ "State",
+ "Country",
+ "Phone",
+ "Homepage",
+ "About",
+ "Gender",
+ "Age",
+ "FullName",
+ "Uid",
+ "DisplayName",
+ NULL
+};
+
static int db_GetContactInfo(lua_State *L)
{
MCONTACT hContact = luaL_checkinteger(L, 1);
int type = 0;
- if (lua_isnumber(L, 2))
- type = lua_tointeger(L, 2);
- else if (lua_isstring(L, 2))
+ switch (lua_type(L, 2))
{
- const char *key = luaL_checkstring(L, 2);
-
- if (mir_strcmpi(key, "FirstName") == 0)
- type = CNF_FIRSTNAME;
- else if (mir_strcmpi(key, "LastName") == 0)
- type = CNF_LASTNAME;
- else if (mir_strcmpi(key, "Nick") == 0)
- type = CNF_NICK;
- else if (mir_strcmpi(key, "CustomNick") == 0)
- type = CNF_CUSTOMNICK;
- else if (mir_strcmpi(key, "FullName") == 0)
- type = CNF_FIRSTLAST;
- else if (mir_strcmpi(key, "DisplayName") == 0)
- type = CNF_DISPLAY;
- else if (mir_strcmpi(key, "Uid") == 0)
- type = CNF_UNIQUEID;
- else if (mir_strcmpi(key, "Email") == 0)
- type = CNF_EMAIL;
- else if (mir_strcmpi(key, "City") == 0)
- type = CNF_CITY;
- else if (mir_strcmpi(key, "State") == 0)
- type = CNF_STATE;
- else if (mir_strcmpi(key, "Country") == 0)
- type = CNF_COUNTRY;
- else if (mir_strcmpi(key, "Phone") == 0)
- type = CNF_PHONE;
- else if (mir_strcmpi(key, "Homepage") == 0)
- type = CNF_HOMEPAGE;
- else if (mir_strcmpi(key, "About") == 0)
- type = CNF_ABOUT;
- else if (mir_strcmpi(key, "Age") == 0)
- type = CNF_AGE;
- else if (mir_strcmpi(key, "Gender") == 0)
- type = CNF_GENDER;
- else
- {
- lua_pushnil(L);
- return 1;
- }
+ case LUA_TNUMBER:
+ type = luaL_checkinteger(L, 2);
+ break;
+ case LUA_TSTRING:
+ type = luaL_checkoption(L, 2, NULL, mods) + 1;
+ break;
+ default:
+ luaL_argerror(L, 1, luaL_typename(L, 2));
}
ptrW value(Contact_GetInfo(type, hContact));
diff --git a/plugins/MirLua/src/m_hotkeys.cpp b/plugins/MirLua/src/m_hotkeys.cpp index 63358fd31c..2b2aed8c18 100644 --- a/plugins/MirLua/src/m_hotkeys.cpp +++ b/plugins/MirLua/src/m_hotkeys.cpp @@ -36,11 +36,7 @@ void MakeHotkey(lua_State *L, HOTKEYDESC &hk) static int hotkeys_Register(lua_State *L)
{
- if (lua_type(L, 1) != LUA_TTABLE)
- {
- lua_pushlightuserdata(L, 0);
- return 1;
- }
+ luaL_checktype(L, 1, LUA_TTABLE);
HOTKEYDESC hk;
MakeHotkey(L, hk);
@@ -56,7 +52,9 @@ static int hotkeys_Register(lua_State *L) static int hotkeys_Unregister(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
+
Hotkey_Unregister(name);
+
return 0;
}
|