refactoring
This commit is contained in:
+12
-13
@@ -51,16 +51,14 @@ do
|
||||
|
||||
function public.modifier(f)
|
||||
local function apply(_, value) return f(value) end
|
||||
return setmetatable(t, {
|
||||
__call=apply, __sub=apply, __pow=apply, __newindex=function(_, _, value) return f(value) end,
|
||||
})
|
||||
return setmetatable(t, {__call=apply, __sub=apply, __pow=apply, __newindex=function(_, _, value) return f(value) end})
|
||||
end
|
||||
local temp, perm = modifier(function(t) transient[t] = true end), modifier(function(t) transient[t] = nil; return t end)
|
||||
local temp, perm = modifier(function(t) transient[t] = true return t end), modifier(function(t) transient[t] = nil; return t end)
|
||||
function public.accessor.temp() return temp end; function mutator(t) return temp(t) end
|
||||
function public.accessor.perm() return perm end; function mutator(t) return perm(t) end
|
||||
|
||||
local function keys(t,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20)
|
||||
if not t then return end
|
||||
local function keys(t,k1,k2,k3,k4,k5,k6,k7,k8,k9,k10,k11,k12,k13,k14,k15,k16,k17,k18,k19,k20,overflow)
|
||||
assert(overflow == nil, 'Overflow.')
|
||||
if k1 ~= nil then t[k1] = true end
|
||||
if k2 ~= nil then t[k2] = true end
|
||||
if k3 ~= nil then t[k3] = true end
|
||||
@@ -83,8 +81,8 @@ do
|
||||
if k20 ~= nil then t[k20] = true end
|
||||
return t
|
||||
end
|
||||
local function values(t,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20)
|
||||
if not t then return end
|
||||
local function values(t,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,overflow)
|
||||
assert(overflow == nil, 'Overflow.')
|
||||
if v1 ~= nil then tinsert(t, v1) end
|
||||
if v2 ~= nil then tinsert(t, v2) end
|
||||
if v3 ~= nil then tinsert(t, v3) end
|
||||
@@ -107,8 +105,8 @@ do
|
||||
if v20 ~= nil then tinsert(t, v20) end
|
||||
return t
|
||||
end
|
||||
local function pairs(t,k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9,v9,k10,v10)
|
||||
if not t then return end
|
||||
local function pairs(t,k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9,v9,k10,v10,overflow)
|
||||
assert(overflow == nil, 'Overflow.')
|
||||
if k1 ~= nil then t[k1] = v1 end
|
||||
if k2 ~= nil then t[k2] = v2 end
|
||||
if k3 ~= nil then t[k3] = v3 end
|
||||
@@ -121,7 +119,7 @@ do
|
||||
if k10 ~= nil then t[k10] = v10 end
|
||||
return t
|
||||
end
|
||||
function public.collector_mt(f)
|
||||
local function collector_mt(f)
|
||||
return {__call=f, __unm=function(self) return setmetatable(self, nil) end}
|
||||
end
|
||||
local set_mt, list_mt, object_mt = collector_mt(keys), collector_mt(values), collector_mt(pairs)
|
||||
@@ -164,8 +162,9 @@ end
|
||||
|
||||
tab_info = t
|
||||
do
|
||||
local data = temp-list('search_tab', 'Search', 'post_tab', 'Post', 'auctions_tab', 'Auctions', 'bids_tab', 'Bids')
|
||||
for i=1,7,2 do
|
||||
local data = -temp^list('search_tab', 'Search', 'post_tab', 'Post', 'auctions_tab', 'Auctions', 'bids_tab', 'Bids')
|
||||
for i=1,getn(data),2 do
|
||||
log(data[i], data[i + 1])
|
||||
local tab = -object('name', data[i + 1])
|
||||
local env = (function() module(data[i]) return _m end)()
|
||||
function env.mutator.OPEN(f) tab.OPEN = f end
|
||||
|
||||
@@ -108,6 +108,7 @@ function module(name)
|
||||
metadata = {_=MUTABLE, _g=PRIVATE, _m=PRIVATE, _i=PRIVATE, import=PRIVATE, private=PROPERTY+ACCESSOR, public=PROPERTY+ACCESSOR, mutable=PROPERTY+ACCESSOR, accessor=PROPERTY+ACCESSOR+MUTATOR, mutator=PROPERTY+ACCESSOR+MUTATOR},
|
||||
data = {_g=_g, _m=env, _i=interface, import=importer}, accessors=accessors, mutators=mutators,
|
||||
}
|
||||
if not name then error('kek', 2) end
|
||||
_modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state
|
||||
importer [''] 'core'
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@ RESULTS, SAVED, FILTER = 1, 2, 3
|
||||
|
||||
function LOAD()
|
||||
create_frames()
|
||||
set_tab(SAVED)
|
||||
set_subtab(SAVED)
|
||||
update_auto_buy_filter()
|
||||
new_search ''
|
||||
current_search.placeholder = true
|
||||
@@ -78,7 +78,7 @@ function USE_ITEM(item_info)
|
||||
execute(nil, false)
|
||||
end
|
||||
|
||||
function set_tab(tab)
|
||||
function set_subtab(tab)
|
||||
|
||||
search_results_button:UnlockHighlight()
|
||||
saved_searches_button:UnlockHighlight()
|
||||
|
||||
@@ -247,7 +247,7 @@ function create_frames()
|
||||
btn:SetWidth(243)
|
||||
btn:SetHeight(22)
|
||||
btn:SetText 'Search Results'
|
||||
btn:SetScript('OnClick', function() set_tab(RESULTS) end)
|
||||
btn:SetScript('OnClick', function() set_subtab(RESULTS) end)
|
||||
search_results_button = btn
|
||||
end
|
||||
do
|
||||
@@ -256,7 +256,7 @@ function create_frames()
|
||||
btn:SetWidth(243)
|
||||
btn:SetHeight(22)
|
||||
btn:SetText 'Saved Searches'
|
||||
btn:SetScript('OnClick', function() set_tab(SAVED) end)
|
||||
btn:SetScript('OnClick', function() set_subtab(SAVED) end)
|
||||
saved_searches_button = btn
|
||||
end
|
||||
do
|
||||
@@ -265,7 +265,7 @@ function create_frames()
|
||||
btn:SetWidth(243)
|
||||
btn:SetHeight(22)
|
||||
btn:SetText 'Filter Builder'
|
||||
btn:SetScript('OnClick', function() set_tab(FILTER) end)
|
||||
btn:SetScript('OnClick', function() set_subtab(FILTER) end)
|
||||
new_filter_button = btn
|
||||
end
|
||||
do
|
||||
|
||||
@@ -66,13 +66,13 @@ do
|
||||
function previous_search()
|
||||
search_box:ClearFocus()
|
||||
update_search(search_index - 1)
|
||||
set_tab(RESULTS)
|
||||
set_subtab(RESULTS)
|
||||
end
|
||||
|
||||
function next_search()
|
||||
search_box:ClearFocus()
|
||||
update_search(search_index + 1)
|
||||
set_tab(RESULTS)
|
||||
set_subtab(RESULTS)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -267,7 +267,7 @@ function start_search(queries, continuation)
|
||||
search.status_bar:set_text 'Scan complete'
|
||||
|
||||
if current_search == search and frame.results:IsVisible() and getn(search.records) == 0 then
|
||||
set_tab(SAVED)
|
||||
set_subtab(SAVED)
|
||||
end
|
||||
|
||||
search.active = false
|
||||
@@ -348,7 +348,7 @@ function public.execute(resume, real_time)
|
||||
current_search.active = true
|
||||
update_start_stop()
|
||||
|
||||
set_tab(RESULTS)
|
||||
set_subtab(RESULTS)
|
||||
if real_time then
|
||||
start_real_time_scan(queries[1], nil, continuation)
|
||||
else
|
||||
|
||||
+15
-15
@@ -45,7 +45,7 @@ public.filters = {
|
||||
},
|
||||
|
||||
['left'] = {
|
||||
input_type = {'30m', '2h', '8h', '24h'},
|
||||
input_type = -list('30m', '2h', '8h', '24h'),
|
||||
validator = function(index)
|
||||
return function(auction_record)
|
||||
return auction_record.duration == index
|
||||
@@ -54,7 +54,7 @@ public.filters = {
|
||||
},
|
||||
|
||||
['rarity'] = {
|
||||
input_type = {'poor', 'common', 'uncommon', 'rare', 'epic'},
|
||||
input_type = -list('poor', 'common', 'uncommon', 'rare', 'epic'),
|
||||
validator = function(index)
|
||||
return function(auction_record)
|
||||
return auction_record.quality == index - 1
|
||||
@@ -207,11 +207,11 @@ public.filters = {
|
||||
}
|
||||
|
||||
function operator(str)
|
||||
local operator = str == 'not' and {'operator', 'not', 1}
|
||||
local operator = str == 'not' and -list('operator', 'not', 1)
|
||||
for name in -set('and', 'or') do
|
||||
for arity in present(select(3, strfind(str, '^'..name..'(%d*)$'))) do
|
||||
arity = tonumber(arity)
|
||||
operator = not (arity and arity < 2) and {'operator', name, arity}
|
||||
operator = not (arity and arity < 2) and -list('operator', name, arity)
|
||||
end
|
||||
end
|
||||
return operator or nil
|
||||
@@ -229,7 +229,7 @@ do
|
||||
end
|
||||
for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do
|
||||
if number >= 1 and number <= 60 then
|
||||
for _, filter in {'min_level', 'max_level'} do
|
||||
for filter in -temp^set('min_level', 'max_level') do
|
||||
if not self[filter] then
|
||||
self[filter] = {str, number}
|
||||
return true
|
||||
@@ -237,12 +237,12 @@ do
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, parser in {
|
||||
{'class', info.item_class_index},
|
||||
{'subclass', L(info.item_subclass_index, index(self.class, 2) or 0, _1)},
|
||||
{'slot', L(info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, _1)},
|
||||
{'quality', info.item_quality_index},
|
||||
} do
|
||||
for _, parser in -list(
|
||||
-list('class', info.item_class_index),
|
||||
-list('subclass', L(info.item_subclass_index, index(self.class, 2) or 0, _1)),
|
||||
-list('slot', L(info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, _1)),
|
||||
-list('quality', info.item_quality_index)
|
||||
) do
|
||||
if not self[parser[1]] then
|
||||
tinsert(parser, str)
|
||||
for index, label in present(parser[2](select(3, unpack(parser)))) do
|
||||
@@ -254,7 +254,7 @@ do
|
||||
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
|
||||
self[str] = {str, 1}
|
||||
elseif i == 1 and strlen(str) <= 63 then
|
||||
self.name = {str, unquote(str)}
|
||||
self.name = -list(str, unquote(str))
|
||||
-- return nil, 'The name filter must not be longer than 63 characters'
|
||||
else
|
||||
return
|
||||
@@ -304,14 +304,14 @@ function public.parse_query_string(str)
|
||||
return nil, 'Invalid input for '..parts[i]..'. Expecting: '..input_type
|
||||
end
|
||||
end
|
||||
tinsert(post_filter, {'filter', parts[i], parts[i + 1]})
|
||||
tinsert(post_filter, -list('filter', parts[i], parts[i + 1]))
|
||||
i = i + 1
|
||||
else
|
||||
tinsert(post_filter, {'filter', parts[i]})
|
||||
tinsert(post_filter, -list('filter', parts[i]))
|
||||
end
|
||||
elseif not blizzard_filter_parser(parts[i], i) then
|
||||
if parts[i] ~= '' then
|
||||
tinsert(post_filter, {'filter', 'tooltip', parts[i]})
|
||||
tinsert(post_filter, -list('filter', 'tooltip', parts[i]))
|
||||
else
|
||||
return nil, 'Empty modifier'
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user