Mercurial > wow > reaction
diff classes/Bar.lua @ 241:09c8e9baa35a
Collect table utility functions
author | Flick |
---|---|
date | Fri, 25 Mar 2011 16:50:43 -0700 |
parents | 704f4a05a1d7 |
children | b56cff349bd6 |
line wrap: on
line diff
--- a/classes/Bar.lua Fri Mar 25 16:42:21 2011 -0700 +++ b/classes/Bar.lua Fri Mar 25 16:50:43 2011 -0700 @@ -7,6 +7,8 @@ local floor = math.floor local fmod = math.fmod local format = string.format +local tfetch = addonTable.tfetch +local fieldsort = addonTable.fieldsort local LSG = LibStub("ReAction-LibShowActionGrid-1.0") @@ -145,42 +147,6 @@ } ----- Utility functions ---- - --- traverse a table tree by key list and fetch the result or first nil -local function tfetch(t, ...) - for i = 1, select('#', ...) do - t = t and t[select(i, ...)] - end - return t -end - --- traverse a table tree by key list and build tree as necessary -local function tbuild(t, ...) - for i = 1, select('#', ...) do - local key = select(i, ...) - if not t[key] then t[key] = { } end - t = t[key] - end - return t -end - --- return a new array of keys of table 't', sorted by comparing --- sub-fields (obtained via tfetch) of the table values -local function fieldsort( t, ... ) - local r = { } - for k in pairs(t) do - table.insert(r,k) - end - local path = { ... } - table.sort(r, function(lhs, rhs) - local olhs = tfetch(t[lhs], unpack(path)) or 0 - local orhs = tfetch(t[rhs], unpack(path)) or 0 - return olhs < orhs - end) - return r -end - ---- Bar class ---- local Bar = { }