Code: Select all
local function findIndexForNewElement(parent, order)
local index = 1
for i=1,#parent.children do
if (parent.children[i].tags['order'] or "") < order then
index = index + 1
else
break
end
end
return index
end
local order = "a"
parent.add{
-- ...
tags = {order = order},
index = findIndexForNewElement(parent, order)
}