From 406c82ece26d3999dd692e4ac229821b51e51924 Mon Sep 17 00:00:00 2001 From: "Erik L. Vonderscheer" Date: Thu, 30 Jul 2009 04:22:17 +0000 Subject: [PATCH] Keep lists sorted! --- Docs/changelog.txt | 2 ++ TradeFilter3.lua | 18 ++++++++++++++++++ TradeFilter3Options.lua | 10 +++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Docs/changelog.txt b/Docs/changelog.txt index 90fe6d5..0ce7a90 100644 --- a/Docs/changelog.txt +++ b/Docs/changelog.txt @@ -1,4 +1,6 @@ == ChangeLog +*r159 +**++Keep lists sorted!++ *r155 **++LDB support for Repeats Blocked++ **++Ability for Whitelist to bypass repeat filter++ diff --git a/TradeFilter3.lua b/TradeFilter3.lua index 30503f5..d22843f 100644 --- a/TradeFilter3.lua +++ b/TradeFilter3.lua @@ -238,6 +238,24 @@ function TF3:RecycleTables(t, state) end end +function TF3:pairsByKeys(t, f) + local a = {} + for n in pairs(t) do + table.insert(a, n) + end + table.sort(a, f) + local i = 0 -- iterator variable + local iter = function() -- iterator function + i = i + 1 + if a[i] == nil then + return nil + else + return a[i], t[a[i]] + end + end + return iter +end + --[[ Friends Functions ]]-- function TF3:GetFriends() local friends = TF3.db.profile.friendslist diff --git a/TradeFilter3Options.lua b/TradeFilter3Options.lua index e3899c2..5f83b11 100644 --- a/TradeFilter3Options.lua +++ b/TradeFilter3Options.lua @@ -148,7 +148,7 @@ options = { if (TF3.db.profile.filters.SPECIAL == nil) then TF3.db.profile.filters.SPECIAL = L.FILTERS.SPECIAL end - for k, v in pairs(TF3.db.profile.filters.SPECIAL) do + for k,v in TF3:pairsByKeys(TF3.db.profile.filters.SPECIAL) do if ret == "" then ret = v else @@ -213,7 +213,7 @@ options = { if (TF3.db.profile.filters.TRADE == nil) then TF3.db.profile.filters.TRADE = L.FILTERS.TRADE end - for k, v in pairs(TF3.db.profile.filters.TRADE) do + for k,v in TF3:pairsByKeys(TF3.db.profile.filters.TRADE) do if ret == "" then ret = v else @@ -262,7 +262,7 @@ options = { if (TF3.db.profile.filters.BASE == nil) then TF3.db.profile.filters.BASE = L.FILTERS.BASE end - for k, v in pairs(TF3.db.profile.filters.BASE) do + for k,v in TF3:pairsByKeys(TF3.db.profile.filters.BASE) do if ret == "" then ret = v else @@ -340,7 +340,7 @@ options = { if (TF3.db.profile.blacklist == nil) then TF3.db.profile.blacklist = L.BLACKLIST end - for k, v in pairs(TF3.db.profile.blacklist) do + for k,v in TF3:pairsByKeys(TF3.db.profile.blacklist) do if ret == "" then ret = v else @@ -415,7 +415,7 @@ options = { if (TF3.db.profile.whitelist == nil) then TF3.db.profile.whitelist = L.WHITELIST end - for k, v in pairs(TF3.db.profile.whitelist) do + for k,v in TF3:pairsByKeys(TF3.db.profile.whitelist) do if ret == "" then ret = v else -- 1.7.9.5