Пример #1
0
/** Define a global key binding. This key binding will always be available.
 * \param L The Lua VM state.
 *
 * \luastack
 * \lparam A table with modifier keys.
 * \lparam A key name.
 * \lparam A function to execute.
 * \lreturn The keybinding.
 */
static int
luaA_keybinding_new(lua_State *L)
{
    size_t i, len;
    keybinding_t *k;
    const char *key;

    /* arg 2 is key mod table */
    luaA_checktable(L, 2);
    /* arg 3 is key */
    key = luaL_checklstring(L, 3, &len);
    /* arg 4 is cmd to run */
    luaA_checkfunction(L, 4);

    /* get the last arg as function */
    k = p_new(keybinding_t, 1);
    luaA_keystore(k, key, len);
    luaA_registerfct(L, 4, &k->fct);

    len = lua_objlen(L, 2);
    for(i = 1; i <= len; i++)
    {
        size_t blen;
        lua_rawgeti(L, 2, i);
        key = luaL_checklstring(L, -1, &blen);
        k->mod |= xutil_key_mask_fromstr(key, blen);
    }

    return luaA_keybinding_userdata_new(L, k);
}
Пример #2
0
/** Take a modifier table from the stack and return modifiers mask.
 * \param L The Lua VM state.
 * \param ud The index of the table.
 * \return The mask value.
 */
uint16_t
luaA_tomodifiers(lua_State *L, int ud)
{
    luaA_checktable(L, ud);
    ssize_t len = luaA_rawlen(L, ud);
    uint16_t mod = XCB_NONE;
    for(int i = 1; i <= len; i++)
    {
        lua_rawgeti(L, ud, i);
        const char *key = luaL_checkstring(L, -1);
        mod |= xutil_key_mask_fromstr(key);
        lua_pop(L, 1);
    }
    return mod;
}