From e8ec24dacc09aac7796e1277962f5f8febc97615 Mon Sep 17 00:00:00 2001 From: Rahix Date: Wed, 17 Apr 2019 02:55:15 +0200 Subject: [PATCH] Small refactor Signed-off-by: Rahix --- bc.lua | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/bc.lua b/bc.lua index f2ff898f4b4a..c05b70b31c91 100644 --- a/bc.lua +++ b/bc.lua @@ -280,25 +280,23 @@ function BaseControl:set(name, value) local old = self.local_nouns[name] self.local_nouns[name] = value - if self.listeners[name] ~= nil then - for id, l in pairs(self.listeners[name]) do - if (l.query.ty == Query.Change.ty and value ~= old) - or (l.query.ty == Query.Rising.ty and value > old) - or (l.query.ty == Query.Falling.ty and value < old) - or (l.query.ty == Query.Equals.ty and value == l.query.v) - or (l.query.ty == Query.Above.ty and value > l.query.v) - or (l.query.ty == Query.Below.ty and value < l.query.v) - then - if l.callback ~= nil then - l.callback(value) - else - self.network:send(l.addr, { - ty=Message.ListenNotify, - noun=name, - id=id, - value=value, - }) - end + for id, l in pairs(self.listeners[name] or {}) do + if (l.query.ty == Query.Change.ty and value ~= old) + or (l.query.ty == Query.Rising.ty and value > old) + or (l.query.ty == Query.Falling.ty and value < old) + or (l.query.ty == Query.Equals.ty and value == l.query.v) + or (l.query.ty == Query.Above.ty and value > l.query.v) + or (l.query.ty == Query.Below.ty and value < l.query.v) + then + if l.callback ~= nil then + l.callback(value) + else + self.network:send(l.addr, { + ty=Message.ListenNotify, + noun=name, + id=id, + value=value, + }) end end end