aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-09-18 11:17:45 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-09-18 11:17:45 +0300
commitb98fe9cb0128175f48ed2a51fecc2ae37592e3f9 (patch)
tree69ac5bf5c54bde4b1ce0e0626daa41b7ec477c6d
parent0e56b133ce4dbe78eecbe910cd18f7ac0ebed137 (diff)
downloadawall-b98fe9cb0128175f48ed2a51fecc2ae37592e3f9.tar.bz2
awall-b98fe9cb0128175f48ed2a51fecc2ae37592e3f9.tar.xz
ConfigObject.uniqueid: allow an empty key
-rw-r--r--awall/model.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/awall/model.lua b/awall/model.lua
index f4ed958..c49daa5 100644
--- a/awall/model.lua
+++ b/awall/model.lua
@@ -29,6 +29,15 @@ local maplist = util.maplist
local startswith = require('stringy').startswith
+local function join(a, b)
+ local comps = {}
+ local function add(s) if s and s > '' then table.insert(comps, s) end end
+ add(a)
+ add(b)
+ if comps[1] then return table.concat(comps, '-') end
+end
+
+
M.ConfigObject = M.class()
function M.ConfigObject:init(context, location)
@@ -58,9 +67,7 @@ function M.ConfigObject:create(cls, params, label, index)
end
end
- local lbl = {self.label}
- table.insert(lbl, label)
- if lbl[1] then params.label = table.concat(lbl, '-') end
+ params.label = join(self.label, label)
local obj = cls.morph(params, self.context, self.location)
if key then self.extraobjs[key] = obj end
@@ -68,13 +75,13 @@ function M.ConfigObject:create(cls, params, label, index)
end
function M.ConfigObject:uniqueid(key)
+ if not key then key = '' end
if self.uniqueids[key] then return self.uniqueids[key] end
if not self.context.lastid then self.context.lastid = {} end
local lastid = self.context.lastid
- local res = key
- if self.label then res = res..'-'..self.label end
+ local res = join(key, self.label)
if not lastid[res] then lastid[res] = -1 end
lastid[res] = lastid[res] + 1
res = res..'-'..lastid[res]