Commit 16e25b4f authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

util.extend helper function

parent 7a202674
......@@ -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)
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment