diff options
-rw-r--r-- | awall/model.lua | 12 | ||||
-rw-r--r-- | awall/util.lua | 8 |
2 files changed, 10 insertions, 10 deletions
diff --git a/awall/model.lua b/awall/model.lua index 43da388..3665d7f 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -150,9 +150,7 @@ function Rule:zoneoptfrags() for i = 1,math.max(1, table.maxn(self.out)) do ozone = self.out[i] if izone ~= ozone or not izone then - for i, ofrags in ipairs(zonepair(izone, ozone)) do - table.insert(res, ofrags) - end + util.extend(res, zonepair(izone, ozone)) end end end @@ -183,9 +181,7 @@ function Rule:servoptfrags() if new or ports[sdef.proto][1] then if sdef.port then - for i, port in util.listpairs(sdef.port) do - table.insert(ports[sdef.proto], port) - end + util.extend(ports[sdef.proto], sdef.port) else ports[sdef.proto] = {} end end @@ -329,9 +325,7 @@ function Rule:trules() end end - for i, ofrag in ipairs(ffilter(self:extraoptfrags())) do - table.insert(res, ofrag) - end + util.extend(res, ffilter(self:extraoptfrags())) tag(res, 'table', self:table(), false) diff --git a/awall/util.lua b/awall/util.lua index 19a003d..f5afb37 100644 --- a/awall/util.lua +++ b/awall/util.lua @@ -9,7 +9,9 @@ module(..., package.seeall) local function list(var) if not var then return {} end - return type(var) == 'table' and var[1] and var or {var} + if type(var) ~= 'table' then return {var} end + if not next(var) then return {} end + return var[1] and var or {var} end function listpairs(var) @@ -31,3 +33,7 @@ function contains(tbl, value) for k, v in pairs(tbl) do if v == value then return true end end return false end + +function extend(tbl1, tbl2) + for i, var in listpairs(tbl2) do table.insert(tbl1, var) end +end |