From 879a43fbc4a51a12cb40b8faaa76253832e57cda Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 5 Apr 2014 23:54:04 -0400 Subject: [PATCH] Add ability to track connections One interesting use case for this is to only do expensive operations if something is connected to the signal: -- item:connect_signal("connection",function(_,name,count) -- if name == "mouse::move" and count == 0 then -- widget:connect_signal("mouse::move",conn) -- end -- end) -- item:connect_signal("disconnection",function(_,name,count) -- if count == 0 then -- widget:connect_signal("mouse::move",conn) -- end -- end) --- object.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/object.lua b/object.lua index 6bb686c..a894821 100644 --- a/object.lua +++ b/object.lua @@ -11,12 +11,14 @@ local function setup_object(args) function data:connect_signal(name,func) signals[name] = signals[name] or {} table.insert(signals[name],func) + data:emit_signal("connection",name,#signals[name]) end function data:disconnect_signal(name,func) for k,v in pairs(signals[name] or {}) do if v == func then signals[name][k] = nil + data:emit_signal("disconnection",name,#signals[name]) end end end