/* Add a signal to an object. * `oud` is the object index on the stack. * `name` is the name of the signal. * `ud` is the index of function to call when signal is emitted. */ void luaH_object_add_signal(lua_State *L, gint oud, const gchar *name, gint ud) { luaH_checkfunction(L, ud); lua_object_t *obj = lua_touserdata(L, oud); signal_add(obj->signals, name, luaH_object_ref_item(L, oud, ud)); }
/* Add a global signal. * Returns the number of elements pushed on stack. * \luastack * \lparam A string with the event name. * \lparam The function to call. */ static gint luaH_luakit_add_signal(lua_State *L) { const gchar *name = luaL_checkstring(L, 1); luaH_checkfunction(L, 2); signal_add(globalconf.signals, name, luaH_object_ref(L, 2)); return 0; }
/* Remove a signal to an object. * `oud` is the object index on the stack. * `name` is the name of the signal. * `ud` is the index of function to call when signal is emitted. */ void luaH_object_remove_signal(lua_State *L, gint oud, const gchar *name, gint ud) { luaH_checkfunction(L, ud); lua_object_t *obj = lua_touserdata(L, oud); gpointer ref = (gpointer) lua_topointer(L, ud); signal_remove(obj->signals, name, ref); luaH_object_unref_item(L, oud, ref); lua_remove(L, 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 gint luaH_luakit_remove_signal(lua_State *L) { const gchar *name = luaL_checkstring(L, 1); luaH_checkfunction(L, 2); gpointer func = (gpointer) lua_topointer(L, 2); signal_remove(globalconf.signals, name, func); luaH_object_unref(L, (void *) func); return 0; }
/* Add a signal to an object. * `oud` is the object index on the stack. * `name` is the name of the signal. * `ud` is the index of function to call when signal is emitted. */ void luaH_object_add_signal(lua_State *L, gint oud, const gchar *name, gint ud) { luaH_checkfunction(L, ud); lua_object_t *obj = lua_touserdata(L, oud); gchar *origin = luaH_callerinfo(L); debug("add " ANSI_COLOR_BLUE "\"%s\"" ANSI_COLOR_RESET " on %p from " ANSI_COLOR_GREEN "%s" ANSI_COLOR_RESET, name, obj, origin); g_free(origin); signal_add(obj->signals, name, luaH_object_ref_item(L, oud, ud)); }