Keep lists sorted!
Erik L. Vonderscheer [07-30-09 - 04:22]
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