Ejemplo n.º 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);
}
Ejemplo n.º 2
0
static int
luaA_key_set_key(lua_State *L, keyb_t *k)
{
    size_t klen;
    const char *key = luaL_checklstring(L, -1, &klen);
    luaA_keystore(L, -3, key, klen);
    return 0;
}