Also make gears.object more object-y
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
90f7f55348
commit
5ea174782d
|
@ -33,43 +33,39 @@ local function find_signal(obj, name, error_msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Add a signal to an object. All signals must be added before they can be used.
|
--- Add a signal to an object. All signals must be added before they can be used.
|
||||||
-- @param obj The object
|
|
||||||
-- @param name The name of the new signal.
|
-- @param name The name of the new signal.
|
||||||
function object.add_signal(obj, name)
|
function object:add_signal(name)
|
||||||
check(obj)
|
check(self)
|
||||||
if not obj._signals[name] then
|
if not self._signals[name] then
|
||||||
obj._signals[name] = {}
|
self._signals[name] = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Connect to a signal
|
--- Connect to a signal
|
||||||
-- @param obj The object
|
|
||||||
-- @param name The name of the signal
|
-- @param name The name of the signal
|
||||||
-- @param func The callback to call when the signal is emitted
|
-- @param func The callback to call when the signal is emitted
|
||||||
function object.connect_signal(obj, name, func)
|
function object:connect_signal(name, func)
|
||||||
local sig = find_signal(obj, name, "connect to")
|
local sig = find_signal(self, name, "connect to")
|
||||||
sig[func] = func
|
sig[func] = func
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Disonnect to a signal
|
--- Disonnect to a signal
|
||||||
-- @param obj The object
|
|
||||||
-- @param name The name of the signal
|
-- @param name The name of the signal
|
||||||
-- @param func The callback that should be disconnected
|
-- @param func The callback that should be disconnected
|
||||||
function object.disconnect_signal(obj, name, func)
|
function object:disconnect_signal(name, func)
|
||||||
local sig = find_signal(obj, name, "disconnect from")
|
local sig = find_signal(self, name, "disconnect from")
|
||||||
sig[func] = nil
|
sig[func] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Emit a signal
|
--- Emit a signal
|
||||||
-- @param obj The object
|
|
||||||
-- @param name The name of the signal
|
-- @param name The name of the signal
|
||||||
-- @param ... Extra arguments for the callback functions. Each connected
|
-- @param ... Extra arguments for the callback functions. Each connected
|
||||||
-- function receives the object as first argument and then any extra
|
-- function receives the object as first argument and then any extra
|
||||||
-- arguments that are given to emit_signal()
|
-- arguments that are given to emit_signal()
|
||||||
function object.emit_signal(obj, name, ...)
|
function object:emit_signal(name, ...)
|
||||||
local sig = find_signal(obj, name, "emit")
|
local sig = find_signal(self, name, "emit")
|
||||||
for func in pairs(sig) do
|
for func in pairs(sig) do
|
||||||
func(obj, ...)
|
func(self, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue