object: Add support for signal forwarding
The CAPI signal system already has this mechanism.
This commit is contained in:
parent
a20dd4ad61
commit
ce3be7ca1b
|
@ -56,6 +56,11 @@ function object:connect_signal(name, func)
|
|||
sig.strong[func] = true
|
||||
end
|
||||
|
||||
-- Register a global signal receiver.
|
||||
function object:_connect_everything(callback)
|
||||
table.insert(self._global_receivers, callback)
|
||||
end
|
||||
|
||||
local function make_the_gc_obey(func)
|
||||
if _VERSION <= "Lua 5.1" then
|
||||
-- Lua 5.1 only has the behaviour we want if a userdata is used as the
|
||||
|
@ -120,6 +125,9 @@ function object:emit_signal(name, ...)
|
|||
for func in pairs(sig.weak) do
|
||||
func(self, ...)
|
||||
end
|
||||
for _, func in ipairs(self._global_receivers) do
|
||||
func(name, self, ...)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_miss(self, key)
|
||||
|
@ -188,6 +196,8 @@ local function new(args)
|
|||
|
||||
ret._signals = {}
|
||||
|
||||
ret._global_receivers = {}
|
||||
|
||||
local mt = {}
|
||||
|
||||
-- Look for methods in another table
|
||||
|
|
Loading…
Reference in New Issue