diff classes/State.lua @ 241:09c8e9baa35a

Collect table utility functions
author Flick
date Fri, 25 Mar 2011 16:50:43 -0700
parents 98d7ad4a1158
children b56cff349bd6
line wrap: on
line diff
--- a/classes/State.lua	Fri Mar 25 16:42:21 2011 -0700
+++ b/classes/State.lua	Fri Mar 25 16:50:43 2011 -0700
@@ -11,6 +11,8 @@
 local format = string.format
 local InCombatLockdown = InCombatLockdown
 local RegisterStateDriver = RegisterStateDriver
+local tfetch = addonTable.tfetch
+local tbuild = addonTable.tbuild
 
 -- module declaration
 local moduleID = "State"
@@ -18,39 +20,6 @@
 
 -- Utility --
 
--- 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
 
 
 local ApplyStates, CleanupStates, SetProperty, GetProperty