diff options
Diffstat (limited to 'plugins/MirLua/src/m_hotkeys.cpp')
-rw-r--r-- | plugins/MirLua/src/m_hotkeys.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/plugins/MirLua/src/m_hotkeys.cpp b/plugins/MirLua/src/m_hotkeys.cpp index 030107ebb6..9cd4ad3aa7 100644 --- a/plugins/MirLua/src/m_hotkeys.cpp +++ b/plugins/MirLua/src/m_hotkeys.cpp @@ -36,7 +36,7 @@ void MakeHotkey(lua_State *L, HOTKEYDESC &hk) lua_pop(L, 1);
}
-static int lua_Register(lua_State *L)
+static int hotkeys_Register(lua_State *L)
{
if (lua_type(L, 1) != LUA_TTABLE)
{
@@ -46,25 +46,47 @@ static int lua_Register(lua_State *L) HOTKEYDESC hk;
MakeHotkey(L, hk);
- INT_PTR res = ::CallService("CoreHotkeys/Register", (WPARAM)hLangpack, (LPARAM)&hk);
+
+ INT_PTR res = ::CallService("CoreHotkeys/Register", (WPARAM)g_mLua->GetHLangpack(), (LPARAM)&hk);
lua_pushboolean(L, res);
return 1;
}
-static int lua_Unregister(lua_State *L)
+static int hotkeys_Unregister(lua_State *L)
{
const char *name = luaL_checkstring(L, 1);
- ::CallService(MS_HOTKEY_UNREGISTER, 0, (LPARAM)name);
+ CallService(MS_HOTKEY_UNREGISTER, 0, (LPARAM)name);
return 0;
}
-static int lua_MakeHotkey(lua_State *L)
+static const char *mods[] = { "shift", "ctrl", "alt", "ext", NULL };
+
+static int hotkeys_MakeHotkey(lua_State *L)
{
- int mod = luaL_checkinteger(L, 1);
- int vk = luaL_checkinteger(L, 2);
+ int mod = 0;
+ switch (lua_type(L, 1))
+ {
+ case LUA_TNUMBER:
+ mod = luaL_checkinteger(L, 1);
+ break;
+ case LUA_TSTRING:
+ mod = (1 << (luaL_checkoption(L, 1, NULL, mods) - 1));
+ break;
+ case LUA_TTABLE:
+ lua_pushnil(L);
+ while (lua_next(L, 1) != 0)
+ {
+ mod |= (1 << (luaL_checkoption(L, -1, NULL, mods) - 1));
+ lua_pop(L, 1);
+ }
+ break;
+ default:
+ luaL_argerror(L, 1, luaL_typename(L, 1));
+ }
+ int vk = luaL_checknumber(L, 2);
WORD res = HOTKEYCODE(mod, vk);
lua_pushinteger(L, res);
@@ -74,9 +96,9 @@ static int lua_MakeHotkey(lua_State *L) static luaL_Reg hotkeysApi[] =
{
- { "MakeHotkey", lua_MakeHotkey },
- { "Register", lua_Register },
- { "Unregister", lua_Unregister },
+ { "MakeHotkey", hotkeys_MakeHotkey },
+ { "Register", hotkeys_Register },
+ { "Unregister", hotkeys_Unregister },
{ NULL, NULL }
};
|