/** 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); }
/** Add a global signal. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lparam A string with the event name. * \lparam The function to call. */ static int luaA_awesome_add_signal(lua_State *L) { const char *name = luaL_checkstring(L, 1); luaA_checkfunction(L, 2); signal_add(&global_signals, name, luaA_object_ref(L, 2)); return 0; }
/** Add a signal to an object. * \param L The Lua VM state. * \param oud The object index on the stack. * \param name The name of the signal. * \param ud The index of function to call when signal is emitted. */ void luaA_object_add_signal(lua_State *L, int oud, const char *name, int ud) { luaA_checkfunction(L, ud); lua_object_t *obj = lua_touserdata(L, oud); signal_add(&obj->signals, name, luaA_object_ref_item(L, oud, ud)); }
/** Remove a global signal. * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack * \lparam A string with the event name. * \lparam The function to call. */ static int luaA_awesome_remove_signal(lua_State *L) { const char *name = luaL_checkstring(L, 1); luaA_checkfunction(L, 2); const void *func = lua_topointer(L, 2); signal_remove(&global_signals, name, func); luaA_object_unref(L, (void *) func); return 0; }
/** Remove a signal to an object. * \param L The Lua VM state. * \param oud The object index on the stack. * \param name The name of the signal. * \param ud The index of function to call when signal is emitted. */ void luaA_object_remove_signal(lua_State *L, int oud, const char *name, int ud) { luaA_checkfunction(L, ud); lua_object_t *obj = lua_touserdata(L, oud); void *ref = (void *) lua_topointer(L, ud); signal_remove(&obj->signals, name, ref); luaA_object_unref_item(L, oud, ref); lua_remove(L, ud); }