object: Add support for signal forwarding

The CAPI signal system already has this mechanism.
This commit is contained in:
Emmanuel Lepage Vallee 2017-07-15 23:15:29 -04:00
parent a20dd4ad61
commit ce3be7ca1b
1 changed files with 10 additions and 0 deletions

View File

@ -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