key: change setmodifiers to tomodifiers

This is more Lua compliant.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-06-17 17:05:47 +02:00
parent 5c775b06c0
commit 5eadbc0116
3 changed files with 14 additions and 12 deletions

View File

@ -83,8 +83,7 @@ luaA_button_new(lua_State *L)
button->press = press;
button->release = release;
button->button = xbutton;
luaA_setmodifiers(L, 2, &button->mod);
button->mod = luaA_tomodifiers(L, 2);
return 1;
}
@ -196,7 +195,8 @@ luaA_button_newindex(lua_State *L)
button->button = luaL_checknumber(L, 3);
break;
case A_TK_MODIFIERS:
luaA_setmodifiers(L, 3, &button->mod);
button->mod = luaA_tomodifiers(L, 3);
break;
default:
break;
}

16
key.c
View File

@ -1046,7 +1046,7 @@ luaA_key_new(lua_State *L)
k->press = press;
k->release = release;
luaA_setmodifiers(L, 2, &k->mod);
k->mod = luaA_tomodifiers(L, 2);
return 1;
}
@ -1110,24 +1110,26 @@ luaA_pushmodifiers(lua_State *L, uint16_t modifiers)
return 1;
}
/** Take a modifier table from the stack and set modifiers in mod.
/** Take a modifier table from the stack and return modifiers mask.
* \param L The Lua VM state.
* \param ud The index of the table.
* \param mod Where to set the modifiers.
* \return The mask value.
*/
void
luaA_setmodifiers(lua_State *L, int ud, uint16_t *mod)
uint16_t
luaA_tomodifiers(lua_State *L, int ud)
{
luaA_checktable(L, ud);
ssize_t len = lua_objlen(L, ud);
uint16_t mod = XCB_NONE;
for(int i = 1; i <= len; i++)
{
lua_rawgeti(L, ud, i);
size_t blen;
const char *key = luaL_checklstring(L, -1, &blen);
*mod |= xutil_key_mask_fromstr(key, blen);
mod |= xutil_key_mask_fromstr(key, blen);
lua_pop(L, 1);
}
return mod;
}
/** Key object.
@ -1213,7 +1215,7 @@ luaA_key_newindex(lua_State *L)
}
break;
case A_TK_MODIFIERS:
luaA_setmodifiers(L, 3, &k->mod);
k->mod = luaA_tomodifiers(L, 3);
break;
case A_TK_PRESS:
luaA_registerfct(L, 3, &k->press);

4
key.h
View File

@ -1,7 +1,7 @@
/*
* key.h - Keybinding helpers
*
* Copyright © 2008 Pierre Habouzit <madcoder@debian.org>
* Copyright © 2009 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -49,6 +49,6 @@ int luaA_key_array_get(lua_State *, key_array_t *);
void window_grabkeys(xcb_window_t, key_array_t *);
int luaA_pushmodifiers(lua_State *, uint16_t);
void luaA_setmodifiers(lua_State *, int, uint16_t *);
uint16_t luaA_tomodifiers(lua_State *L, int ud);
#endif