I have the following structure
self.modules = { ["Announcements"] = { priority = 0, -- Tons of other attributes }, ["Healthbar"] = { priority = 40, -- Tons of other attributes }, ["Powerbar"] = { priority = 35, -- Tons of other attributes }, }
I need to sort this table by priorty DESC, other values ββdon't matter. For instance. First go to the Health panel, then Powerbar, and then go on to everyone else.
// edit.
Keys must be saved.
// edit # 2
Found a solution, thanks to everyone.
local function pairsByPriority(t) local registry = {} for k, v in pairs(t) do tinsert(registry, {k, v.priority}) end tsort(registry, function(a, b) return a[2] > b[2] end) local i = 0 local iter = function() i = i + 1 if (registry[i] ~= nil) then return registry[i][1], t[registry[i][1]] end return nil end return iter end
source share