refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-28 02:23:38 +02:00
parent 15e6e7409a
commit f42e54a4fc
15 changed files with 78 additions and 77 deletions
+4 -3
View File
@@ -57,6 +57,7 @@ do
-- log(getn(table_pool), '-', getn(weak_pool))
end
function public.t.get()
return tremove(pool) or tremove(overflow_pool, next(overflow_pool)) or {}
end
@@ -171,7 +172,7 @@ end
function public.log(...) temp=arg
local msg = '[aux]'
for i=1,arg.n do msg = msg..' '..tostring(arg[i]) end
for i = 1, arg.n do msg = msg..' '..tostring(arg[i]) end
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg)
end
@@ -363,7 +364,7 @@ do
local id = GetCraftSelectionIndex()
local reagent_count = GetCraftNumReagents(id)
local total_cost = 0
for i=1,reagent_count do
for i = 1, reagent_count do
local link = GetCraftReagentItemLink(id, i)
if not link then
total_cost = nil
@@ -390,7 +391,7 @@ do
local id = GetTradeSkillSelectionIndex()
local reagent_count = GetTradeSkillNumReagents(id)
local total_cost = 0
for i=1,reagent_count do
for i = 1, reagent_count do
local link = GetTradeSkillReagentItemLink(id, i)
if not link then
total_cost = nil
+2 -2
View File
@@ -65,7 +65,7 @@ do
end
function merchant_loaded()
for i=1,GetMerchantNumItems() do
for i = 1, GetMerchantNumItems() do
if not GetMerchantItemLink(i) then
return false
end
@@ -107,7 +107,7 @@ end
function merchant_buy_scan()
local incomplete_data
for i=1,GetMerchantNumItems() do
for i = 1, GetMerchantNumItems() do
local _, _, price, count, stock = GetMerchantItemInfo(i)
local link = GetMerchantItemLink(i)
if link then
+1 -1
View File
@@ -224,7 +224,7 @@ function wait_for_list_results(send_signal, signal_received)
end
function owner_data_complete(type)
for i=1,PAGE_SIZE do
for i = 1, PAGE_SIZE do
local auction_info = info.auction(i, type)
if auction_info and not auction_info.owner then
return false
+2 -2
View File
@@ -53,7 +53,7 @@ function _G.SlashCmdList.AUX(command)
elseif arguments[1] == 'chars' and arguments[2] == 'add' then
local realm = GetCVar 'realmName'
_G.aux_characters[realm] = _G.aux_characters[realm] or {}
for i=3,getn(arguments) do
for i = 3, getn(arguments) do
local name = gsub(strlower(arguments[i]), '^%l', strupper)
if not _G.aux_characters[realm][name] then
_G.aux_characters[realm][name] = true
@@ -65,7 +65,7 @@ function _G.SlashCmdList.AUX(command)
if not _G.aux_characters[realm] then
return
end
for i=3,getn(arguments) do
for i = 3, getn(arguments) do
local name = gsub(strlower(arguments[i]), '^%l', strupper)
if _G.aux_characters[realm][name] then
_G.aux_characters[realm][name] = nil
+5 -5
View File
@@ -533,7 +533,7 @@ function record_percentage(record)
end
function percentage_color(pct)
for i=1,getn(AUCTION_PCT_COLORS) do
for i = 1, getn(AUCTION_PCT_COLORS) do
if pct < AUCTION_PCT_COLORS[i].value then
return AUCTION_PCT_COLORS[i].color
end
@@ -693,7 +693,7 @@ local methods = {
-- Populate the row info from the database by combining identical auctions and auctions
-- of the same base item. Also, get the number of rows which will be shown.
for i=1, getn(records) do
for i = 1, getn(records) do
local record = records[i]
local prevRecord = records[i-1]
if prevRecord and record.search_signature == prevRecord.search_signature then
@@ -903,7 +903,7 @@ local methods = {
RemoveSelectedRecord = function(self, count)
count = count or 1
for i=1, count do
for i = 1, count do
local index = key(self.selected, self.records)
if index then
tremove(self.records, index)
@@ -914,7 +914,7 @@ local methods = {
InsertAuctionRecord = function(self, record, count)
count = count or 1
for i=1, count do
for i = 1, count do
tinsert(self.records, record)
end
self:SetDatabase()
@@ -1089,7 +1089,7 @@ function public.CreateAuctionResultsTable(parent, config)
-- create the rows
rt.rows = {}
for i=1, numRows do
for i = 1, numRows do
local row = CreateFrame('Frame', nil, rt.contentFrame)
row:SetHeight(rt.ROW_HEIGHT)
if i == 1 then
+3 -3
View File
@@ -32,7 +32,7 @@ function LOAD()
DropDownList1:SetHeight(DropDownList1:GetHeight() - 10)
DropDownList1:ClearAllPoints()
DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, -2)
for i=1,UIDROPDOWNMENU_MAXBUTTONS do
for i = 1, UIDROPDOWNMENU_MAXBUTTONS do
local button = _G['DropDownList1Button'..i]
button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7)
button:SetPoint('TOPRIGHT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7)
@@ -57,7 +57,7 @@ function LOAD()
DropDownList1Backdrop:SetBackdrop(blizzard_backdrop)
aux_border:Hide()
aux_background:Hide()
for i=1,UIDROPDOWNMENU_MAXBUTTONS do
for i = 1, UIDROPDOWNMENU_MAXBUTTONS do
local button = _G['DropDownList1Button'..i]
local text = button:GetFontString()
text:SetFont([[Fonts\FRIZQT__.ttf]], 10)
@@ -100,7 +100,7 @@ do
orig = menu:GetScript 'OnShow'
menu:SetScript('OnShow', function()
UIMenu_Initialize()
for i=1,getn(structure) do
for i = 1, getn(structure) do
UIMenu_AddButton(
structure[i][1],
structure[i],
+2 -2
View File
@@ -104,7 +104,7 @@ local methods = {
st.updateSort = nil
end
for i=1, st.sizes.numRows do
for i = 1, st.sizes.numRows do
st.rows[i].data = nil
if i > getn(st.rowData) then
st.rows[i]:Hide()
@@ -375,7 +375,7 @@ local methods = {
row.cols = {}
st.rows[rowNum] = row
for i=1, getn(st.colInfo) do
for i = 1, getn(st.colInfo) do
st:AddRowCol(rowNum)
end
end,
+44 -44
View File
@@ -12,7 +12,7 @@ local function collision_error(key) error('"%s" already exists.', key) end
local function nop() end
local function const(v) return function() return v end end
local _state = {}
local state = {}
local declarator_mt = {__metatable=false}
do
@@ -23,86 +23,86 @@ do
if next(v) or f ~= nil and getter ~= nil then error() end
return f, getter, setter
end
local function declare(state, access, name, handlers)
state.access[name] = state.access[name] and collision_error(name) or access or PRIVATE
local function declare(self, access, name, handlers)
self.access[name] = self.access[name] and collision_error(name) or access or PRIVATE
for event, handler in handlers do
if type(handler) ~= 'function' and (event == INDEX or declaration_error()) then
handler = const(handler == nil and tostring(name) or handler)
end
state[event][name] = handler
self[event][name] = handler
end
end
function declarator_mt:__index(key) local state=_state[self]
if ACCESS[key] and not state.declaration_access then
state.declaration_access = ACCESS[key]
elseif not state.declaration_name or declaration_error() then
state.declaration_name = type(key) == 'string' and key or declaration_error()
function declarator_mt:__index(key) self=state[self]
if ACCESS[key] and not self.declaration_access then
self.declaration_access = ACCESS[key]
elseif not self.declaration_name or declaration_error() then
self.declaration_name = type(key) == 'string' and key or declaration_error()
end
return self
return self.declarator
end
function declarator_mt:__newindex(key, value) local state=_state[self]
local name, event = state.declaration_name, nil
function declarator_mt:__newindex(key, value) self=state[self]
local name, event = self.declaration_name, nil
if name then
event = EVENT[key] or declaration_error()
else
name, event = key, type(value) == 'function' and CALL or INDEX
end
declare(state, state.declaration_access, name, {[event]=value})
state.declaration_access, state.declaration_name = nil, nil
declare(self, self.declaration_access, name, {[event]=value})
self.declaration_access, self.declaration_name = nil, nil
end
function declarator_mt:__call(value) local state=_state[self]
if state.declaration_name then
function declarator_mt:__call(value) self=state[self]
if self.declaration_name then
local success, f, getter, setter = pcall(extract, value)
if not success then declaration_error() end
declare(state, state.declaration_access, state.declaration_name, {[CALL]=f, [INDEX]=getter, [NEWINDEX]=setter})
declare(self, self.declaration_access, self.declaration_name, {[CALL]=f, [INDEX]=getter, [NEWINDEX]=setter})
end
state.declaration_access, state.declaration_name = nil, nil
self.declaration_access, self.declaration_name = nil, nil
end
end
local env_mt = {__metatable=false}
function env_mt:__index(key) local state=_state[self]
local getter = state[INDEX][key]
function env_mt:__index(key) self=state[self]
local getter = self[INDEX][key]
if getter then return getter() end
return state[CALL][key] or _G[key] or state.declarator[key]
return self[CALL][key] or _G[key] or self.declarator[key]
end
function env_mt:__newindex(key, value) local state=_state[self]
if state.access[key] then
local setter = state[NEWINDEX][key] or collision_error(key)
function env_mt:__newindex(key, value) self=state[self]
if self.access[key] then
local setter = self[NEWINDEX][key] or collision_error(key)
setter(value)
else
state.declarator[key] = value
self.declarator[key] = value
end
end
local interface_mt = {__metatable=false}
function interface_mt:__index(key) local state=_state[self]
if state.access[key] == PUBLIC then
local getter = state[INDEX][key]
if getter then return getter() else return state[CALL][key] end
function interface_mt:__index(key) self=state[self]
if self.access[key] == PUBLIC then
local getter = self[INDEX][key]
if getter then return getter() else return self[CALL][key] end
end
end
function interface_mt:__newindex(key, value) local state=_state[self]
if state.access[key] == PUBLIC then (state[NEWINDEX][key] or nop)(value) end
function interface_mt:__newindex(key, value) self=state[self]
if self.access[key] == PUBLIC then (self[NEWINDEX][key] or nop)(value) end
end
function module(...)
local state, declarator, env, interface, access, functions, getters, setters
declarator, env, interface = setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
access = {_=PRIVATE, error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE}
functions = {error=error, nop=nop}
getters = {_G=const(_G), M=const(env), I=const(interface), public=function() return declarator.public end, private=function() return declarator.private end}
setters = {_=nop}
for i=1,arg.n do
local module = _state[arg[i] or import_error()] or import_error()
local module_functions, module_getters, module_setters = module[CALL], module[INDEX], module[NEWINDEX]
local declarator, env, interface = setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
local self = {
access = {_=PRIVATE, error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE},
[CALL] = {error=error, nop=nop},
[INDEX] = {_G=const(_G), M=const(env), I=const(interface), public=function() return declarator.public end, private=function() return declarator.private end},
[NEWINDEX] = {_=nop},
declarator = declarator,
}
for i = 1, arg.n do
local module = state[arg[i] or import_error()]
for k, v in module.access do
if v == PUBLIC and (not access[k] or import_error()) then
access[k], functions[k], getters[k], setters[k] = PRIVATE, module_functions[k], module_getters[k], module_setters[k]
if v == PUBLIC and not self.access[k] then
self.access[k], self[CALL][k], self[INDEX][k], self[NEWINDEX][k] = PRIVATE, module[CALL][k], module[INDEX][k], module[NEWINDEX][k]
end
end
end
state = {access=access, [CALL]=functions, [INDEX]=getters, [NEWINDEX]=setters, declarator=declarator}
_state[declarator], _state[env], _state[interface] = state, state, state
state[declarator], state[env], state[interface] = self, self, self
setfenv(2, env)
end
+2 -2
View File
@@ -221,7 +221,7 @@ function post_auctions()
unit_buyout_price,
stack_count,
function(posted)
for i=1,posted do
for i = 1, posted do
record_auction(key, stack_size, unit_start_price, unit_buyout_price, duration_code, UnitName('player'))
end
update_inventory_records()
@@ -405,7 +405,7 @@ function update_inventory_records()
if info.auctionable(item_info.tooltip, nil, item_info.lootable) then
if not auctionable_map[item_info.item_key] then
local availability = t
for i=0,10 do
for i = 0, 10 do
availability[i] = 0
end
availability[charge_class] = item_info.count
+1 -1
View File
@@ -388,7 +388,7 @@ function initialize_quality_dropdown()
update_form()
end
UIDropDownMenu_AddButton(-object('text', ALL, 'value', -1, 'func', on_click))
for i=0,4 do
for i = 0, 4 do
UIDropDownMenu_AddButton(-object('text', _G['ITEM_QUALITY'..i..'_DESC'], 'value', i, 'func', on_click))
end
end
+1 -1
View File
@@ -227,7 +227,7 @@ function start_search(queries, continuation)
if continuation then
start_query, start_page = unpack(continuation)
for i=1,start_query-1 do
for i = 1, start_query - 1 do
tremove(queries, 1)
end
queries[1].blizzard_query.first_page = (queries[1].blizzard_query.first_page or 0) + start_page - 1
+4 -4
View File
@@ -20,14 +20,14 @@ end
do
local formal_parameters = t
for i=1,9 do
for i = 1, 9 do
local key = '_'..i
public[key] = t
formal_parameters[M[key]] = i
end
local function helper(f, arg1, arg2)
local params = t
for i=1,arg1.n do
for i = 1, arg1.n do
if formal_parameters[arg1[i]] then
tinsert(params, arg2[formal_parameters[arg1[i]]])
else
@@ -58,7 +58,7 @@ function public.call(f, ...) temp=arg
end
function public.index(t, ...) temp=arg
for i=1,arg.n do
for i = 1, arg.n do
t = t and t[arg[i]]
end
return t
@@ -94,7 +94,7 @@ end
function public.expand(array, ...) temp=arg
local t = t
for i=1,arg.n do t[arg[i]] = array[i] end
for i = 1, arg.n do t[arg[i]] = array[i] end
return t
end
+2 -2
View File
@@ -402,7 +402,7 @@ function suggestions(components)
-- rarities
if not components.blizzard.quality then
for i=0,4 do tinsert(suggestions, _G['ITEM_QUALITY'..i..'_DESC']) end
for i = 0, 4 do tinsert(suggestions, _G['ITEM_QUALITY'..i..'_DESC']) end
end
-- item names
@@ -534,7 +534,7 @@ function validator(components)
return false
end
local stack = {}
for i=getn(components.post),1,-1 do
for i = getn(components.post), 1, -1 do
local type, name, param = unpack(components.post[i])
if type == 'operator' then
local args = {}
+3 -3
View File
@@ -236,7 +236,7 @@ function public.load_tooltip(frame, tooltip)
frame:AddLine(line.left_text, line.left_color[1], line.left_color[2], line.left_color[3], true)
end
end
for i=1,getn(tooltip) do -- TODO why is this needed?
for i = 1, getn(tooltip) do -- TODO why is this needed?
_G[frame:GetName()..'TextLeft'..i]:SetJustifyH('LEFT')
_G[frame:GetName()..'TextRight'..i]:SetJustifyH('LEFT')
end
@@ -273,7 +273,7 @@ function public.tooltip(setter)
AuxTooltip:Show()
local tooltip = t
for i=1,AuxTooltip:NumLines() do
for i = 1, AuxTooltip:NumLines() do
tinsert(tooltip, {
left_text = _G['AuxTooltipTextLeft'..i]:GetText(),
left_color = {_G['AuxTooltipTextLeft'..i]:GetTextColor()},
@@ -395,7 +395,7 @@ function public.item_slot_index(class_index, subclass_index, slot_name)
end
function public.item_quality_index(item_quality)
for i=0,4 do
for i = 0, 4 do
local quality = _G['ITEM_QUALITY'..i..'_DESC']
if strupper(item_quality) == strupper(quality) then
return i, quality
+2 -2
View File
@@ -69,7 +69,7 @@ function public.read_record(schema, str)
local separator = schema[2]
local record = t
local parts = split(str, separator)
for i=3,getn(schema) do
for i = 3, getn(schema) do
local key, type = next(schema[i])
record[key] = read(type, parts[i - 2])
end
@@ -79,7 +79,7 @@ end
function public.write_record(schema, record)
local separator = schema[2]
local parts = tt
for i=3,getn(schema) do
for i = 3, getn(schema) do
local key, type = next(schema[i])
tinsert(parts, write(type, record[key]))
end