Merge pull request #2015 from Elv13/doc_tests_and_notif_p1_5

object: Add support for signal forwarding
This commit is contained in:
Daniel Hahler 2017-10-21 19:20:41 +02:00 committed by GitHub
commit 03580db5bb
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