2018-07-24 14:27:41 +02:00
|
|
|
--DOC_GEN_OUTPUT --DOC_HIDE
|
2016-05-17 06:59:48 +02:00
|
|
|
local gears = require("gears") --DOC_HIDE
|
|
|
|
|
|
|
|
local o = gears.object{}
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2017-04-08 10:00:34 +02:00
|
|
|
-- Add a __tostring metamethod for prettier output --DOC_HIDE
|
|
|
|
getmetatable(o).__tostring = function() --DOC_HIDE
|
|
|
|
return "[obj]" --DOC_HIDE
|
|
|
|
end --DOC_HIDE
|
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
-- Function can be attached to signals
|
2016-05-17 06:59:48 +02:00
|
|
|
local function slot(obj, a, b, c)
|
|
|
|
print("In slot", obj, a, b, c)
|
|
|
|
end
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-05-17 06:59:48 +02:00
|
|
|
o:connect_signal("my_signal", slot)
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
-- Emitting can be done without arguments. In that case, the object will be
|
|
|
|
-- implicitly added as an argument.
|
2016-05-17 06:59:48 +02:00
|
|
|
o:emit_signal "my_signal"
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
-- It is also possible to add as many random arguments are required.
|
2016-05-17 06:59:48 +02:00
|
|
|
o:emit_signal("my_signal", "foo", "bar", 42)
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-12-27 21:39:08 +01: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`
|
2016-05-17 06:59:48 +02:00
|
|
|
o:disconnect_signal("my_signal", slot)
|
2016-11-21 22:38:23 +01:00
|
|
|
|
2016-12-27 21:39:08 +01:00
|
|
|
-- This time, the `slot` wont be called as it is no longer connected.
|
2016-05-17 06:59:48 +02:00
|
|
|
o:emit_signal "my_signal"
|
2016-12-31 13:59:38 +01:00
|
|
|
|
|
|
|
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|