awesome/tests/examples/text/gears/object/signal.lua

25 lines
765 B
Lua
Raw Normal View History

2016-05-17 06:59:48 +02:00
local gears = require("gears") --DOC_HIDE
local o = gears.object{}
2016-05-17 06:59:48 +02:00
-- Function can be attached to signals
local function slot(obj, a, b, c)
print("In slot", obj, a, b, c)
end
2016-05-17 06:59:48 +02:00
o:connect_signal("my_signal", slot)
-- Emitting can be done without arguments. In that case, the object will be
2016-05-17 06:59:48 +02:00
-- implicitly added as an argument.
o:emit_signal "my_signal"
2016-05-17 06:59:48 +02:00
-- It is also possible to add as many random arguments are required.
o:emit_signal("my_signal", "foo", "bar", 42)
2016-05-17 06:59:48 +02:00
-- Finally, to allow the object to be garbage collected (the memory freed), it
-- is necessary to disconnect the signal or use `weak_connect_signal`
o:disconnect_signal("my_signal", slot)
2016-05-17 06:59:48 +02:00
-- This time, the `slot` wont be called as it is no longer connected.
o:emit_signal "my_signal"