Mercurial > wow > reaction
comparison classes/Bar.lua @ 241:09c8e9baa35a
Collect table utility functions
| author | Flick |
|---|---|
| date | Fri, 25 Mar 2011 16:50:43 -0700 |
| parents | 704f4a05a1d7 |
| children | b56cff349bd6 |
comparison
equal
deleted
inserted
replaced
| 240:98d7ad4a1158 | 241:09c8e9baa35a |
|---|---|
| 5 local _G = _G | 5 local _G = _G |
| 6 local CreateFrame = CreateFrame | 6 local CreateFrame = CreateFrame |
| 7 local floor = math.floor | 7 local floor = math.floor |
| 8 local fmod = math.fmod | 8 local fmod = math.fmod |
| 9 local format = string.format | 9 local format = string.format |
| 10 local tfetch = addonTable.tfetch | |
| 11 local fieldsort = addonTable.fieldsort | |
| 10 | 12 |
| 11 local LSG = LibStub("ReAction-LibShowActionGrid-1.0") | 13 local LSG = LibStub("ReAction-LibShowActionGrid-1.0") |
| 12 | 14 |
| 13 ---- Secure snippets ---- | 15 ---- Secure snippets ---- |
| 14 local _reaction_init = | 16 local _reaction_init = |
| 142 scale = true, | 144 scale = true, |
| 143 enableAlpha = true, | 145 enableAlpha = true, |
| 144 alpha = true, | 146 alpha = true, |
| 145 } | 147 } |
| 146 | 148 |
| 147 | |
| 148 ---- Utility functions ---- | |
| 149 | |
| 150 -- traverse a table tree by key list and fetch the result or first nil | |
| 151 local function tfetch(t, ...) | |
| 152 for i = 1, select('#', ...) do | |
| 153 t = t and t[select(i, ...)] | |
| 154 end | |
| 155 return t | |
| 156 end | |
| 157 | |
| 158 -- traverse a table tree by key list and build tree as necessary | |
| 159 local function tbuild(t, ...) | |
| 160 for i = 1, select('#', ...) do | |
| 161 local key = select(i, ...) | |
| 162 if not t[key] then t[key] = { } end | |
| 163 t = t[key] | |
| 164 end | |
| 165 return t | |
| 166 end | |
| 167 | |
| 168 -- return a new array of keys of table 't', sorted by comparing | |
| 169 -- sub-fields (obtained via tfetch) of the table values | |
| 170 local function fieldsort( t, ... ) | |
| 171 local r = { } | |
| 172 for k in pairs(t) do | |
| 173 table.insert(r,k) | |
| 174 end | |
| 175 local path = { ... } | |
| 176 table.sort(r, function(lhs, rhs) | |
| 177 local olhs = tfetch(t[lhs], unpack(path)) or 0 | |
| 178 local orhs = tfetch(t[rhs], unpack(path)) or 0 | |
| 179 return olhs < orhs | |
| 180 end) | |
| 181 return r | |
| 182 end | |
| 183 | 149 |
| 184 | 150 |
| 185 ---- Bar class ---- | 151 ---- Bar class ---- |
| 186 local Bar = { } | 152 local Bar = { } |
| 187 local frameList = { } | 153 local frameList = { } |
