Commit b98fe9cb authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

ConfigObject.uniqueid: allow an empty key

parent 0e56b133
...@@ -29,6 +29,15 @@ local maplist = util.maplist ...@@ -29,6 +29,15 @@ local maplist = util.maplist
local startswith = require('stringy').startswith 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() M.ConfigObject = M.class()
function M.ConfigObject:init(context, location) function M.ConfigObject:init(context, location)
...@@ -58,9 +67,7 @@ function M.ConfigObject:create(cls, params, label, index) ...@@ -58,9 +67,7 @@ function M.ConfigObject:create(cls, params, label, index)
end end
end end
local lbl = {self.label} params.label = join(self.label, label)
table.insert(lbl, label)
if lbl[1] then params.label = table.concat(lbl, '-') end
local obj = cls.morph(params, self.context, self.location) local obj = cls.morph(params, self.context, self.location)
if key then self.extraobjs[key] = obj end if key then self.extraobjs[key] = obj end
...@@ -68,13 +75,13 @@ function M.ConfigObject:create(cls, params, label, index) ...@@ -68,13 +75,13 @@ function M.ConfigObject:create(cls, params, label, index)
end end
function M.ConfigObject:uniqueid(key) function M.ConfigObject:uniqueid(key)
if not key then key = '' end
if self.uniqueids[key] then return self.uniqueids[key] end if self.uniqueids[key] then return self.uniqueids[key] end
if not self.context.lastid then self.context.lastid = {} end if not self.context.lastid then self.context.lastid = {} end
local lastid = self.context.lastid local lastid = self.context.lastid
local res = key local res = join(key, self.label)
if self.label then res = res..'-'..self.label end
if not lastid[res] then lastid[res] = -1 end if not lastid[res] then lastid[res] = -1 end
lastid[res] = lastid[res] + 1 lastid[res] = lastid[res] + 1
res = res..'-'..lastid[res] res = res..'-'..lastid[res]
......
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