refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-23 08:14:22 +02:00
parent c2f7311349
commit 99ba3e7fdc
15 changed files with 51 additions and 41 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ do
function public.modifier(f) function public.modifier(f)
local function apply(_, value) return f(value) end local function apply(_, value) return f(value) end
return setmetatable(t, { return setmetatable(t, {
__index=apply, __call=apply, __add=apply, __sub=apply, __mul=apply, __div=apply, __pow=apply, __concat=apply, __lt=apply, __le=apply, __index=apply, __call=apply, __add=apply, __sub=apply, __mul=apply, __div=apply, __pow=apply, __concat=apply,
__newindex=function(_, _, value) return f(value) end, __unm=function(self) return self end, __newindex=function(_, _, value) return f(value) end, __unm=function(self) return self end,
}) })
end end
@@ -133,7 +133,7 @@ tab_info = t
do do
local data = -list :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' :bids_tab 'Bids' local data = -list :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' :bids_tab 'Bids'
for i=1,7,2 do for i=1,7,2 do
local tab = perm<-object :name(data[i + 1]); local tab = perm/-object :name(data[i + 1]);
local env = (function() module(data[i]) return _m end)() local env = (function() module(data[i]) return _m end)()
function env.mutator.OPEN(f) tab.OPEN = f end function env.mutator.OPEN(f) tab.OPEN = f end
function env.mutator.CLOSE(f) tab.CLOSE = f end function env.mutator.CLOSE(f) tab.CLOSE = f end
+1
View File
@@ -38,6 +38,7 @@ do
end end
function accessor.state() function accessor.state()
log (thread_id)
local _, state = next(filter(scan_states, function(state) return state.id == thread_id end)) local _, state = next(filter(scan_states, function(state) return state.id == thread_id end))
return state return state
end end
+3 -3
View File
@@ -2,9 +2,9 @@ local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfen
local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16 local PRIVATE, PUBLIC, MUTABLE, PROPERTY, ACCESSOR, MUTATOR = 0, 1, 2, 4, 8, 16
local error, import_error, modifier_error, property_error, immutable_error, collision_error, set_property, env_mt, interface_mt, declarator_mt, importer_mt local error, import_error, modifier_error, property_error, immutable_error, collision_error, set_property, env_mt, interface_mt, declarator_mt, importer_mt
local _state, _modules = {}, {} local _state, _modules = {}, {}
function error(message, ...) return function() _g.error(format(message, unpack(arg))..'\n'..debugstack(3, 10, 0), 0) end end function error(message, ...) return _g.error(format(message, unpack(arg))..'\n'..debugstack(1, 10, 0), 0) end
import_error, modifier_error, property_error = error 'Invalid modifiers.', error 'Invalid modifiers.', error 'Accessor/Mutator must be function.' import_error, modifier_error, property_error = function() error 'Invalid modifiers.' end, function() error 'Invalid modifiers.' end, function() error 'Accessor/Mutator must be function.' end
immutable_error, collision_error = function(key) return error('Field "%s" is immutable.', key) end, function(key) return error('Field "%s" already exists.', key) end immutable_error, collision_error = function(key) error('Field "%s" is immutable.', key) end, function(key) error('Field "%s" already exists.', key) end
importer_mt = {__metatable=false} importer_mt = {__metatable=false}
function importer_mt.__index(self, key) function importer_mt.__index(self, key)
if type(key) ~= 'string' then import_error() end if type(key) ~= 'string' then import_error() end
+1 -1
View File
@@ -1,4 +1,4 @@
module 'auctions_tab' module 'auctions_tab' import 'scan'
auction_records = nil auction_records = nil
+1 -1
View File
@@ -1,4 +1,4 @@
module 'bids_tab' module 'bids_tab' import 'scan'
auction_records = nil auction_records = nil
+2 -2
View File
@@ -1,4 +1,4 @@
module 'post_tab' module 'post_tab' import 'scan' 'post'
local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440 local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440
local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}} local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}}
@@ -88,7 +88,7 @@ end
function update_inventory_listing() function update_inventory_listing()
if not ACTIVE then return end if not ACTIVE then return end
item_listing.populate(item_listing, values(filter(inventory_records, function(record) inventory_listing.populate(inventory_listing, values(filter(inventory_records, function(record)
local settings = read_settings(record.key) local settings = read_settings(record.key)
return record.aux_quantity > 0 and (not settings.hidden or show_hidden_checkbox:GetChecked()) return record.aux_quantity > 0 and (not settings.hidden or show_hidden_checkbox:GetChecked())
end))) end)))
+1 -1
View File
@@ -40,7 +40,7 @@ function create_frames()
gui.horizontal_line(frame.inventory, -48) gui.horizontal_line(frame.inventory, -48)
item_listing = item_listing.create( inventory_listing = item_listing.create(
frame.inventory, frame.inventory,
function() function()
if arg1 == 'LeftButton' then if arg1 == 'LeftButton' then
+1 -1
View File
@@ -1,4 +1,4 @@
module 'search_tab' module 'search_tab' import 'scan'
StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = { StaticPopupDialogs['AUX_SEARCH_TABLE_FULL'] = {
text = 'Table full!\nFurther results from this search will still be processed but no longer displayed in the table.', text = 'Table full!\nFurther results from this search will still be processed but no longer displayed in the table.',
+11 -11
View File
@@ -1,4 +1,4 @@
module 'search_tab' module 'search_tab' import 'filter_util'
function valid_level(str) function valid_level(str)
local level = tonumber(str) local level = tonumber(str)
@@ -109,8 +109,8 @@ function get_filter_builder_query()
end end
local name = blizzard_query.name local name = blizzard_query.name
if not index(filter.parse_query_string(name), 'blizzard', 'name') then if not index(filter_util.parse_query_string(name), 'blizzard', 'name') then
name = filter.quote(name) name = filter_util.quote(name)
end end
add((name ~= '' or blizzard_query.exact) and name) add((name ~= '' or blizzard_query.exact) and name)
@@ -134,7 +134,7 @@ function get_filter_builder_query()
add(strlower(_g['ITEM_QUALITY'..quality..'_DESC'])) add(strlower(_g['ITEM_QUALITY'..quality..'_DESC']))
end end
local post_filter_string = filter.query_string{blizzard={}, post=post_filter} local post_filter_string = filter_util.query_string{blizzard={}, post=post_filter}
add(post_filter_string ~= '' and post_filter_string) add(post_filter_string ~= '' and post_filter_string)
return query_string or '' return query_string or ''
@@ -171,7 +171,7 @@ function clear_form()
end end
function import_query_string() function import_query_string()
local components, error = filter.parse_query_string(select(3, strfind(search_box:GetText(), '^([^;]*)'))) local components, error = filter_util.parse_query_string(select(3, strfind(search_box:GetText(), '^([^;]*)')))
if components then if components then
set_form(components) set_form(components)
else else
@@ -209,7 +209,7 @@ function public.formatted_post_filter(components)
for parameter in present(component[3]) do for parameter in present(component[3]) do
if component[2] == 'item' then if component[2] == 'item' then
parameter = info.display_name(cache.item_id(parameter)) or '['..parameter..']' parameter = info.display_name(cache.item_id(parameter)) or '['..parameter..']'
elseif filter.filters[component[2]].input_type == 'money' then elseif filter_util.filters[component[2]].input_type == 'money' then
parameter = money.to_string(money.from_string(parameter), nil, true) parameter = money.to_string(money.from_string(parameter), nil, true)
end end
component_text = component_text..filter_color(': ')..parameter component_text = component_text..filter_color(': ')..parameter
@@ -262,13 +262,13 @@ end
function add_post_filter() function add_post_filter()
for str in present(filter_input:GetText()) do for str in present(filter_input:GetText()) do
for filter in present(filter.filters[str]) do for filter in present(filter_util.filters[str]) do
if filter.input_type ~= '' then if filter.input_type ~= '' then
str = str..'/'..filter_parameter_input:GetText() str = str..'/'..filter_parameter_input:GetText()
end end
end end
local components, error, suggestions = filter.parse_query_string(str) local components, error, suggestions = filter_util.parse_query_string(str)
if components and getn(components.blizzard) == 0 and getn(components.post) == 1 then if components and getn(components.blizzard) == 0 and getn(components.post) == 1 then
add_component(components.post[1]) add_component(components.post[1])
@@ -319,15 +319,15 @@ function set_filter_display_offset(x_offset, y_offset)
end end
function initialize_filter_dropdown() function initialize_filter_dropdown()
for _, filter in {'and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity', 'left', 'utilizable', 'discard'} do for _, filter in -list 'and' 'or' 'not' 'min-unit-bid' 'min-unit-buy' 'max-unit-bid' 'max-unit-buy' 'bid-profit' 'buy-profit' 'bid-vend-profit' 'buy-vend-profit' 'bid-dis-profit' 'buy-dis-profit' 'bid-pct' 'buy-pct' 'item' 'tooltip' 'min-lvl' 'max-lvl' 'rarity' 'left' 'utilizable' 'discard' do
UIDropDownMenu_AddButton{ UIDropDownMenu_AddButton{
text = filter, text = filter,
value = filter, value = filter,
func = function() func = function()
filter_input:SetText(this.value) filter_input:SetText(this.value)
if index(filter.filters[this.value], 'input_type') == '' or this.value == 'not' then if index(filter_util.filters[this.value], 'input_type') == '' or this.value == 'not' then
add_post_filter() add_post_filter()
elseif filter.filters[this.value] then elseif filter_util.filters[this.value] then
filter_parameter_input:Show() filter_parameter_input:Show()
filter_parameter_input:SetFocus() filter_parameter_input:SetFocus()
else else
+7 -7
View File
@@ -1,4 +1,4 @@
module 'search_tab' import 'gui' [''] 'core' 'completion' 'listing' 'auction_listing' module 'search_tab' import 'gui' [''] 'core' 'completion' 'listing' 'auction_listing' 'filter_util'
FILTER_SPACING = 28.5 FILTER_SPACING = 28.5
@@ -311,7 +311,7 @@ function create_frames()
btn:SetHeight(24) btn:SetHeight(24)
btn:SetText 'Favorite' btn:SetText 'Favorite'
btn:SetScript('OnClick', function() btn:SetScript('OnClick', function()
local filters = filter.queries(search_box:GetText()) local filters = filter_util.queries(search_box:GetText())
if filters then if filters then
tinsert(_g.aux_favorite_searches, 1, { tinsert(_g.aux_favorite_searches, 1, {
filter_string = search_box:GetText(), filter_string = search_box:GetText(),
@@ -510,13 +510,13 @@ function create_frames()
input:SetPoint('CENTER', filter_dropdown, 'CENTER', 0, 0) input:SetPoint('CENTER', filter_dropdown, 'CENTER', 0, 0)
input:SetWidth(150) input:SetWidth(150)
input:SetScript('OnTabPressed', function() filter_parameter_input:SetFocus() end) input:SetScript('OnTabPressed', function() filter_parameter_input:SetFocus() end)
input.complete = completion.complete(function() return {'and', 'or', 'not', unpack(keys(filter.filters))} end) input.complete = completion.complete(function() return {'and', 'or', 'not', unpack(keys(filter_util.filters))} end)
input.char = function() this:complete() end input.char = function() this:complete() end
input.change = function() input.change = function()
local filter = this:GetText() local text = this:GetText()
if filter.filters[filter] and filter.filters[filter].input_type ~= '' then if filter_util.filters[text] and filter_util.filters[text].input_type ~= '' then
local _, _, suggestions = filter.parse_query_string(filter..'/') local _, _, suggestions = filter_util.parse_query_string(text..'/')
filter_parameter_input:SetNumeric(filter.filters[filter].input_type == 'number') filter_parameter_input:SetNumeric(filter_util.filters[text].input_type == 'number')
filter_parameter_input.complete = completion.complete(function() return suggestions or {} end) filter_parameter_input.complete = completion.complete(function() return suggestions or {} end)
filter_parameter_input:Show() filter_parameter_input:Show()
else else
+2 -2
View File
@@ -113,7 +113,7 @@ end
function update_auto_buy_filter() function update_auto_buy_filter()
if _g.aux_auto_buy_filter ~= '' then if _g.aux_auto_buy_filter ~= '' then
local queries = filter.queries(_g.aux_auto_buy_filter) local queries = filter_util.queries(_g.aux_auto_buy_filter)
if queries then if queries then
if getn(queries) > 1 then if getn(queries) > 1 then
log 'Error: The automatic buyout filter does not support multi-queries' log 'Error: The automatic buyout filter does not support multi-queries'
@@ -308,7 +308,7 @@ function public.execute(resume, real_time)
end end
local filter_string = search_box:GetText() local filter_string = search_box:GetText()
local queries = filter.queries(filter_string) local queries = filter_util.queries(filter_string)
if not queries then if not queries then
return return
elseif real_time then elseif real_time then
+1 -1
View File
@@ -8,7 +8,7 @@ function public:complete_filter()
local filter_string = this:GetText() local filter_string = this:GetText()
local completed_filter_string = ({strfind(filter_string, '([^;]*)/[^/;]*$')})[3] local completed_filter_string = ({strfind(filter_string, '([^;]*)/[^/;]*$')})[3]
local _, suggestions = filter.query(completed_filter_string or '') local _, suggestions = filter_util.query(completed_filter_string or '')
local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$') local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$')
current_modifier = current_modifier or '' current_modifier = current_modifier or ''
+12 -7
View File
@@ -42,6 +42,7 @@ do
local arg1 = arg local arg1 = arg
return function(...) return helper(body, arg1, arg) end return function(...) return helper(body, arg1, arg) end
else else
error(debugstack(1, 10))
body = gsub(body, '_([ab])', function(char) return '_'..a1b2[char] end) body = gsub(body, '_([ab])', function(char) return '_'..a1b2[char] end)
local lambda = loadstring 'return function(_1,_2,_3,_4,_5,_6,_7,_8,_9)'..f..' end' local lambda = loadstring 'return function(_1,_2,_3,_4,_5,_6,_7,_8,_9)'..f..' end'
setfenv(lambda, getfenv(2)) setfenv(lambda, getfenv(2))
@@ -51,11 +52,15 @@ do
end end
function public.call(f, ...) temp=arg function public.call(f, ...) temp=arg
if f then return f(unpack(arg)) end if f then
return f(unpack(arg))
end
end end
function public.index(t, ...) temp=arg function public.index(t, ...) temp=arg
for i=1,arg.n do t = t and t[arg[i]] end for i=1,arg.n do
t = t and t[arg[i]]
end
return t return t
end end
@@ -105,12 +110,12 @@ function public.select(i, ...) temp=arg
return tremove(arg, 1), unpack(arg) return tremove(arg, 1), unpack(arg)
end end
function public.collect(t, ...) temp=arg function public.collect(indices, ...) temp=arg
local T = T local t = _m.t
for _, v in t do for _, v in indices do
tinsert(T, arg[v]) tinsert(t, arg[v])
end end
return T return t
end end
function public.hashset(t) function public.hashset(t)
+5 -1
View File
@@ -1,4 +1,8 @@
module 'filter' module 'filter_util' import 'info' 'cache'
function LOAD()
import 'cache'
end
function default_filter(str) function default_filter(str)
return { return {
+1 -1
View File
@@ -75,7 +75,7 @@ function public.item_query(item_id, first_page, last_page)
local item_info = info.item(item_id) local item_info = info.item(item_id)
if item_info then if item_info then
local query = filter.query(item_info.name..'/exact') local query = filter_util.query(item_info.name..'/exact')
query.blizzard_query.first_page = first_page query.blizzard_query.first_page = first_page
query.blizzard_query.last_page = last_page query.blizzard_query.last_page = last_page
return { return {