annotate sort.lua @ 15:218628cb4a29 v1.2.16.0

removed test button from combat log tab
author yellowfive
date Thu, 10 Jul 2014 15:31:17 -0700
parents ec731d2fe6ba
children e77e01abce98
rev   line source
adam@0 1 local _, AskMrRobot = ...
adam@0 2
adam@0 3 function AskMrRobot.spairs(t, order)
adam@0 4 -- collect the keys
adam@0 5 local keys = {}
adam@0 6 for k in pairs(t) do keys[#keys+1] = k end
adam@0 7
adam@0 8 -- if order function given, sort by it by passing the table and keys a, b,
adam@0 9 -- otherwise just sort the keys
adam@0 10 if order then
adam@0 11 table.sort(keys, function(a,b) return order(t, a, b) end)
adam@0 12 else
adam@0 13 table.sort(keys)
adam@0 14 end
adam@0 15
adam@0 16 -- return the iterator function
adam@0 17 local i = 0
adam@0 18 return function()
adam@0 19 i = i + 1
adam@0 20 if keys[i] then
adam@0 21 return keys[i], t[keys[i]]
adam@0 22 end
adam@0 23 end
adam@0 24 end
adam@0 25
adam@0 26 function AskMrRobot.sortSlots(t)
adam@0 27 return AskMrRobot.spairs(t, function(x, a, b)
adam@0 28 if a == nil and b == nil then return 0 end
adam@0 29 return AskMrRobot.sortedSlots[a] < AskMrRobot.sortedSlots[b]
adam@0 30 end)
adam@0 31 end