From 3f3c7b28fc15cc4c05e5a592b5b0accb31104fe4 Mon Sep 17 00:00:00 2001
From: Manuel Simon Hirsig
Date: Sat, 26 Nov 2016 18:28:01 +0100
Subject: [PATCH] ipairs refactoring
---
core/history.lua | 6 +++---
core/tooltip.lua | 3 ++-
frame.lua | 4 ++--
gui/auction_listing.lua | 29 +++++++++++++++--------------
tabs/post/core.lua | 4 ++--
tabs/search/filter.lua | 8 +++++---
tabs/search/saved.lua | 10 ++++++----
util/completion.lua | 15 ++++++++-------
util/filter.lua | 7 ++++---
9 files changed, 47 insertions(+), 39 deletions(-)
diff --git a/core/history.lua b/core/history.lua
index de24196..90ef580 100644
--- a/core/history.lua
+++ b/core/history.lua
@@ -97,10 +97,10 @@ end
function weighted_median(list)
sort(list, function(a,b) return a.value < b.value end)
local weight = 0
- for _, element in ipairs(list) do
- weight = weight + element.weight
+ for i = 1, getn(list) do
+ weight = weight + list[i].weight
if weight >= .5 then
- return element.value
+ return list[i].value
end
end
end
diff --git a/core/tooltip.lua b/core/tooltip.lua
index 5dc72e0..4bfa36c 100644
--- a/core/tooltip.lua
+++ b/core/tooltip.lua
@@ -73,7 +73,8 @@ function extend_tooltip(tooltip, link, quantity)
if aux_tooltip_disenchant_distribution then
tooltip:AddLine('Disenchants into:', color.tooltip.disenchant.distribution())
sort(distribution, function(a,b) return a.probability > b.probability end)
- for _, event in ipairs(distribution) do
+ for i = 1, getn(distribution) do
+ local event = distribution[i]
tooltip:AddLine(format(' %s%% %s (%s-%s)', event.probability * 100, info.display_name(event.item_id, true) or 'item:' .. event.item_id, event.min_quantity, event.max_quantity), color.tooltip.disenchant.distribution())
end
end
diff --git a/frame.lua b/frame.lua
index ad8c3da..8a6a7b0 100644
--- a/frame.lua
+++ b/frame.lua
@@ -3,8 +3,8 @@ module 'aux'
local gui = require 'aux.gui'
function LOAD()
- for _, info in ipairs(tab_info) do
- tabs:create_tab(info.name)
+ for i = 1, getn(tab_info) do
+ tabs:create_tab(tab_info[i].name)
end
end
diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua
index 116b810..62f2cb5 100644
--- a/gui/auction_listing.lua
+++ b/gui/auction_listing.lua
@@ -12,7 +12,6 @@ local search_tab = require 'aux.tabs.search'
_G.aux_price_per_unit = false
-local RT_COUNT = 1
local HEAD_HEIGHT = 27
local HEAD_SPACE = 2
@@ -714,7 +713,8 @@ local methods = {
end
end
- for _, info in ipairs(self.rowInfo) do
+ for i = 1, getn(self.rowInfo) do
+ local info = self.rowInfo[i]
local totalAuctions, totalPlayerAuctions = 0, 0
for _, childInfo in info.children do
totalAuctions = totalAuctions + childInfo.numAuctions
@@ -781,8 +781,8 @@ local methods = {
return tostring(a) < tostring(b)
end
- for _, info in ipairs(self.rowInfo) do
- sort(info.children, sort_helper)
+ for i = 1, getn(self.rowInfo) do
+ sort(self.rowInfo[i].children, sort_helper)
end
sort(self.rowInfo, sort_helper)
self.isSorted = true
@@ -790,11 +790,13 @@ local methods = {
-- update all the rows
local rowIndex = 1 - FauxScrollFrame_GetOffset(self.scrollFrame)
- for _, info in ipairs(self.rowInfo) do
+ for i = 1, getn(self.rowInfo) do
+ local info = self.rowInfo[i]
if self.expanded[info.expandKey] then
-- show each of the rows for this base item since it's expanded
- for i, childInfo in ipairs(info.children) do
- self:SetRowInfo(rowIndex, childInfo.record, childInfo.numAuctions, 0, i > 1, false, info.expandKey, childInfo.numAuctions)
+ for j = 1, getn(info.children) do
+ local childInfo = info.children[j]
+ self:SetRowInfo(rowIndex, childInfo.record, childInfo.numAuctions, 0, j > 1, false, info.expandKey, childInfo.numAuctions)
rowIndex = rowIndex + 1
end
else
@@ -959,8 +961,8 @@ local methods = {
GetSelection = function(self)
if not self.selected then return end
local selectedData
- for _, info in ipairs(self.rowInfo) do
- for _, childInfo in info.children do
+ for i = 1, getn(self.rowInfo) do
+ for _, childInfo in self.rowInfo[i].children do
if childInfo.record.search_signature == self.selected.search_signature then
selectedData = childInfo
break
@@ -972,8 +974,8 @@ local methods = {
GetTotalAuctions = function(self)
local numResults = 0
- for _, info in ipairs(self.rowInfo) do
- for _, childInfo in info.children do
+ for i = 1, getn(self.rowInfo) do
+ for _, childInfo in self.rowInfo[i].children do
numResults = numResults + childInfo.numAuctions
end
end
@@ -982,8 +984,6 @@ local methods = {
}
function M.CreateAuctionResultsTable(parent, config)
-
- RT_COUNT = RT_COUNT + 1
local rt = CreateFrame('Frame', nil, parent)
rt.config = config
local numRows = 16
@@ -1038,7 +1038,8 @@ function M.CreateAuctionResultsTable(parent, config)
-- create the header cells
rt.headCells = T
- for i, column_config in ipairs(rt.config) do
+ for i = 1, getn(rt.config) do
+ local column_config = rt.config[i]
local cell = CreateFrame('Button', nil, rt.contentFrame)
cell:SetHeight(HEAD_HEIGHT)
if i == 1 then
diff --git a/tabs/post/core.lua b/tabs/post/core.lua
index 6f573fc..a7d2b77 100644
--- a/tabs/post/core.lua
+++ b/tabs/post/core.lua
@@ -115,8 +115,8 @@ function update_auction_listing()
local unit_start_price = get_unit_start_price()
local unit_buyout_price = get_unit_buyout_price()
- for i, auction_record in ipairs(existing_auctions[selected_item.key] or empty) do
-
+ for i = 1, getn(existing_auctions[selected_item.key] or empty) do
+ local auction_record = existing_auctions[selected_item.key][i]
local blizzard_bid_undercut, buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue())
blizzard_bid_undercut = money.from_string(money.to_string(blizzard_bid_undercut, true, nil, 3))
buyout_price_undercut = money.from_string(money.to_string(buyout_price_undercut, true, nil, 3))
diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua
index 5b9554b..1b139e0 100644
--- a/tabs/search/filter.lua
+++ b/tabs/search/filter.lua
@@ -155,7 +155,8 @@ end
function set_form(filter)
clear_form()
- for _, component in ipairs(filter.components) do
+ for i = 1, getn(filter.components) do
+ local component = filter.components[i]
if component[1] == 'blizzard' then
blizzard_query[component[2]] = component[4]
else
@@ -201,13 +202,14 @@ function formatted_post_filter(components)
local stack = temp-T
local str = ''
- for i, component in ipairs(components) do
+ for i = 1, getn(components) do
+ local component = components[i]
if no_line_break then
str = str .. ' '
end
str = str .. '
'
for _ = 1, getn(stack) + 1 do
- str = str .. color.content.background('----')
+ str = str .. color.content.background'----'
end
no_line_break = component[1] == 'operator' and component[2] == 'not'
diff --git a/tabs/search/saved.lua b/tabs/search/saved.lua
index 6204a0f..44e380c 100644
--- a/tabs/search/saved.lua
+++ b/tabs/search/saved.lua
@@ -8,7 +8,8 @@ _G.aux_recent_searches = T
function update_search_listings()
local favorite_search_rows = T
- for i, search in ipairs(aux_favorite_searches) do
+ for i = 1, getn(aux_favorite_searches) do
+ local search = aux_favorite_searches[i]
local name = strsub(search.prettified, 1, 250)
tinsert(favorite_search_rows, O(
'cols', A(O('value', search.auto_buy and color.red'A' or ''), O('value', name)),
@@ -19,11 +20,12 @@ function update_search_listings()
favorite_searches_listing:SetData(favorite_search_rows)
local recent_search_rows = T
- for i, recent_search in ipairs(aux_recent_searches) do
- local name = strsub(recent_search.prettified, 1, 250)
+ for i = 1, getn(aux_recent_searches) do
+ local search = aux_recent_searches[i]
+ local name = strsub(search.prettified, 1, 250)
tinsert(recent_search_rows, O(
'cols', A(O('value', name)),
- 'search', recent_search,
+ 'search', search,
'index', i
))
end
diff --git a/util/completion.lua b/util/completion.lua
index 359dd61..1a83700 100644
--- a/util/completion.lua
+++ b/util/completion.lua
@@ -18,16 +18,16 @@ function M:complete_filter()
local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$')
current_modifier = current_modifier or ''
- for _, suggestion in ipairs(suggestions) do
- if strsub(strupper(suggestion), 1, strlen(current_modifier)) == strupper(current_modifier) then
- this:SetText(strlower(strsub(filter_string, 1, start_index - 1) .. suggestion))
+ for i = 1, getn(suggestions) do
+ if strsub(strupper(suggestions[i]), 1, strlen(current_modifier)) == strupper(current_modifier) then
+ this:SetText(strlower(strsub(filter_string, 1, start_index - 1) .. suggestions[i]))
this:HighlightText(strlen(filter_string), -1)
return
end
end
end
-function M.complete(options)
+function M.complete(candidates)
return function(self)
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
return
@@ -35,9 +35,10 @@ function M.complete(options)
local text = self:GetText()
- for _, item_name in ipairs(options()) do
- if strsub(strupper(item_name), 1, strlen(text)) == strupper(text) then
- self:SetText(strlower(item_name))
+ local t = temp-candidates()
+ for i = 1, getn(t) do
+ if strsub(strupper(t[i]), 1, strlen(text)) == strupper(text) then
+ self:SetText(strlower(t[i]))
self:HighlightText(strlen(text), -1)
return
end
diff --git a/util/filter.lua b/util/filter.lua
index 54757c3..2b2807a 100644
--- a/util/filter.lua
+++ b/util/filter.lua
@@ -340,7 +340,8 @@ function M.query(filter_string)
end
local polish_notation_counter = 0
- for _, component in ipairs(filter.post) do
+ for i = 1, getn(filter.post) do
+ local component = filter.post[i]
if component[1] == 'operator' then
polish_notation_counter = max(polish_notation_counter, 1)
polish_notation_counter = polish_notation_counter + (tonumber(component[2]) or 1) - 1
@@ -370,8 +371,8 @@ end
function M.queries(filter_string)
local parts = split(filter_string, ';')
local queries = T
- for _, str in ipairs(parts) do
- str = trim(str)
+ for i = 1, getn(parts) do
+ local str = trim(parts[i])
local query, _, error = query(str)
if not query then
return nil, error