diff --git a/aux-addon.lua b/aux-addon.lua index a127a12..2d1538f 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -1,18 +1,28 @@ module 'core' public.version = '5.0.0' -public.bids_loaded = false -public.current_owner_page = nil +do + local bids_loaded + public.bids_loaded() + function accessor() return bids_loaded end + function mutator(value) bids_loaded = value end +end +do + local current_owner_page + public.current_owner_page() + function accessor() return current_owner_page end + function mutator(value) current_owner_page = value end +end do - local table_pool, temporary = {}, {} + local table_pool, transient = {}, {} CreateFrame'Frame':SetScript('OnUpdate', function() - for t in temporary do + for t in transient do recycle(t) -- log(getn(table_pool)) end - wipe(temporary) + wipe(transient) end) function public.wipe(t) -- like with a cloth or something @@ -20,11 +30,11 @@ do t[k] = nil end table.setn(t, 0) - setmetatable(t, nil) + return setmetatable(t, nil) end function public.recycle(t) - temporary[t] = nil + transient[t] = nil wipe(t) tinsert(table_pool, t) end @@ -33,9 +43,9 @@ do return tremove(table_pool) or {} end - function public.accessor.tt() -- TODO or 'tmp'? t (and t -> T)? + function public.accessor.tt() local t = tremove(table_pool) or {} - temporary[t] = true + transient[t] = true return t end @@ -46,11 +56,11 @@ do __newindex=function(_, _, value) return f(value) end, __unm=function(self) return self end, }) end - local temp, perm = modifier(function(t) temporary[t] = true; return t end), modifier(function(t) temporary[t] = nil; return t end) - public.temp() -- TODO or 'auto'? + local temp, perm = modifier(function(t) transient[t] = true; return t end), modifier(function(t) transient[t] = nil; return t end) + public.temp() -- TODO or 'auto' 'free' 'release' 'unlock'? function accessor() return temp end function mutator(t) return temp(t) end - public.perm() -- TODO or 'keep' 'hold'?? + public.perm() -- TODO or 'persist' 'lock'?? function accessor() return perm end function mutator(t) return perm(t) end @@ -72,7 +82,7 @@ do do local mt = collector_mt(tinsert) function public.accessor.list() - return setmetatable(tt, mt) + return setmetatable(t, mt) end end do @@ -80,7 +90,7 @@ do rawset(self, value, true) end) function public.accessor.set() - return setmetatable(tt, mt) + return setmetatable(t, mt) end end do @@ -94,13 +104,13 @@ do end end) function public.accessor.object() - return setmetatable(tt, mt) + return setmetatable(t, mt) end end end local event_frame = CreateFrame 'Frame' -for event in set 'ADDON_LOADED' 'VARIABLES_LOADED' 'PLAYER_LOGIN' 'AUCTION_HOUSE_SHOW' 'AUCTION_HOUSE_CLOSED' 'AUCTION_BIDDER_LIST_UPDATE' 'AUCTION_OWNED_LIST_UPDATE' do +for event in temp-set 'ADDON_LOADED' 'VARIABLES_LOADED' 'PLAYER_LOGIN' 'AUCTION_HOUSE_SHOW' 'AUCTION_HOUSE_CLOSED' 'AUCTION_BIDDER_LIST_UPDATE' 'AUCTION_OWNED_LIST_UPDATE' do event_frame:RegisterEvent(event) end @@ -131,9 +141,9 @@ end tab_info = t do - local data = -list :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' :bids_tab 'Bids' + local data = temp-list :search_tab 'Search' :post_tab 'Post' :auctions_tab 'Auctions' :bids_tab 'Bids' for i=1,7,2 do - local tab = perm/-object :name(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 function env.mutator.CLOSE(f) tab.CLOSE = f end diff --git a/control.lua b/control.lua index 09a33e1..1f49c43 100644 --- a/control.lua +++ b/control.lua @@ -1,9 +1,15 @@ module 'core' event_frame = CreateFrame 'Frame' -listeners = t -threads = t -public.thread_id = nil +mutable.listeners = t +mutable.threads = t + +do + local thread_id + public.thread_id() + function accessor() return thread_id end + function mutator(value) thread_id = value end +end function LOAD() event_frame:SetScript('OnUpdate', UPDATE) diff --git a/core/cache.lua b/core/cache.lua index 219e99d..fbe43c0 100644 --- a/core/cache.lua +++ b/core/cache.lua @@ -1,4 +1,4 @@ -module 'cache' +module 'cache' import 'info' MIN_ITEM_ID = 1 MAX_ITEM_ID = 30000 @@ -148,7 +148,7 @@ function merchant_buy_scan() end function merchant_sell_scan() - for slot in inventory do + for slot in info.inventory do local item_info = info.container_item(unpack(slot)) if item_info then _g.aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity diff --git a/core/disenchant.lua b/core/disenchant.lua index aa99dd3..732bf1f 100644 --- a/core/disenchant.lua +++ b/core/disenchant.lua @@ -39,7 +39,7 @@ do end function LOAD() - ARMOR = set + ARMOR = -set 'INVTYPE_HEAD' 'INVTYPE_NECK' 'INVTYPE_SHOULDER' @@ -55,7 +55,7 @@ function LOAD() 'INVTYPE_TRINKET' 'INVTYPE_CLOAK' 'INVTYPE_HOLDABLE' - WEAPON = set + WEAPON = -set 'INVTYPE_2HWEAPON' 'INVTYPE_WEAPONMAINHAND' 'INVTYPE_WEAPON' @@ -80,7 +80,7 @@ end function public.distribution(slot, quality, level) if not (ARMOR[slot] or WEAPON[slot]) or level == 0 then - return tt + return t end local function p(probability_armor, probability_weapon) @@ -191,5 +191,5 @@ function public.distribution(slot, quality, level) return {{item_id=20725, min_quantity=1, max_quantity=2, probability=1}} end end - return tt + return t end \ No newline at end of file diff --git a/core/history.lua b/core/history.lua index b836dd6..7755e23 100644 --- a/core/history.lua +++ b/core/history.lua @@ -1,21 +1,27 @@ -module 'history' +module 'history' import 'persistence' + +--local history_schema = tuple('#') +-- :next_push 'number' +-- :daily_min_buyout 'number' +-- :daily_max_price 'number' +-- :data_points (list(';') (tuple('@') :market_value 'number' :time 'number')) local history_schema = {'record', '#', {next_push='number'}, {daily_min_buyout='number'}, {daily_max_price='number'}, {data_points={'list', ';', {'record', '@', {market_value='number'}, {time='number'}}}}} -value_cache = {} +value_cache = t -function next_push() - local date = date('*t') +function accessor.next_push() + local date = date '*t' date.hour, date.min, date.sec = 24, 0, 0 return time(date) end function new_record() - return { next_push = next_push(), data_points = {} } + return -object :next_push(next_push) :data_points(t) end function load_data() local dataset = persistence.load_dataset() - dataset.history = dataset.history or {} + dataset.history = dataset.history or t return dataset.history end @@ -69,23 +75,22 @@ function public.value(item_key) local value if getn(item_record.data_points) > 0 then - local weighted_values = {} + local weighted_values = tt local total_weight = 0 for _, data_point in item_record.data_points do - local weight = 0.99^round((item_record.data_points[1].time - data_point.time) / (60*60*24)) + local weight = 0.99^round((item_record.data_points[1].time - data_point.time) / (60 * 60 * 24)) total_weight = total_weight + weight - tinsert(weighted_values, {value = data_point.market_value, weight = weight}) + tinsert(weighted_values, -object :value(data_point.market_value) :weight(weight)) end for _, weighted_value in weighted_values do weighted_value.weight = weighted_value.weight / total_weight end - value = weighted_median(weighted_values) else value = calculate_market_value(item_record) end - value_cache[item_key] = {value=value, next_push=item_record.next_push} + value_cache[item_key] = -object :value(value) :next_push(item_record.next_push) end return value_cache[item_key].value @@ -101,7 +106,7 @@ function calculate_market_value(item_record) end function weighted_median(list) - local sorted_list = {} + local sorted_list = tt for _, e in list do tinsert(sorted_list, e) end @@ -120,7 +125,7 @@ function push_record(item_record) local market_value = calculate_market_value(item_record) if market_value then - tinsert(item_record.data_points, 1, { market_value = market_value, time = item_record.next_push }) + tinsert(item_record.data_points, 1, -object :market_value(market_value) :time(item_record.next_push)) while getn(item_record.data_points) > 11 do tremove(item_record.data_points) end @@ -128,5 +133,5 @@ function push_record(item_record) item_record.daily_min_buyout = nil item_record.daily_max_price = nil - item_record.next_push = next_push() + item_record.next_push = next_push end \ No newline at end of file diff --git a/core/scan.lua b/core/scan.lua index ab6ea3c..1eada15 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -1,4 +1,8 @@ -module 'scan' +module 'scan' import 'info' + +function LOAD() + import 'history' +end PAGE_SIZE = 50 @@ -6,7 +10,7 @@ do local scan_states = {} function public.start(params) - for _, old_state in {scan_states[params.type]} do + for old_state in present(scan_states[params.type]) do abort(old_state.id) end local thread_id = thread(L(wait_for_callback, params.on_scan_start, scan)) @@ -38,7 +42,6 @@ do end function accessor.state() - log (thread_id) local _, state = next(filter(scan_states, function(state) return state.id == thread_id end)) return state end diff --git a/core/stack.lua b/core/stack.lua index 5043f7e..eca08d4 100644 --- a/core/stack.lua +++ b/core/stack.lua @@ -1,4 +1,4 @@ -module 'stack' +module 'stack' import 'info' state = nil @@ -23,7 +23,7 @@ function locked(slot) end function find_item_slot(partial) - for slot in inventory do + for slot in info.inventory do if matching_item(slot, partial) and not eq(slot, state.target_slot) then return slot end @@ -36,7 +36,7 @@ function matching_item(slot, partial) end function find_empty_slot() - for slot, type in inventory do + for slot, type in info.inventory do if type == 1 and not GetContainerItemInfo(unpack(slot)) then return slot end @@ -44,7 +44,7 @@ function find_empty_slot() end function find_charge_item_slot() - for slot in inventory do + for slot in info.inventory do if matching_item(slot) and charges(slot) == state.target_size then return slot end diff --git a/core/tooltip.lua b/core/tooltip.lua index feddf22..78ff73d 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -1,4 +1,4 @@ -module 'tooltip' +module 'tooltip' import 'info' _g.aux_tooltip_value = true @@ -232,7 +232,7 @@ end function game_tooltip_hooks:SetAuctionSellItem() local name, _, quantity = GetAuctionSellItemInfo() if name then - for slot in inventory do + for slot in info.inventory do local link = GetContainerItemLink(unpack(slot)) if link and select(5, info.parse_link(link)) == name then extend_tooltip(GameTooltip, link, quantity) diff --git a/module.lua b/module.lua index 3e771af..38d7dd8 100644 --- a/module.lua +++ b/module.lua @@ -2,7 +2,7 @@ local type, setmetatable, setfenv, unpack, mask, _g = type, setmetatable, setfen 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 _state, _modules = {}, {} -function error(message, ...) return _g.error(format(message, unpack(arg))..'\n'..debugstack(1, 10, 0), 0) end +function error(message, ...) return _g.error(format(message, unpack(arg))..'\n'..debugstack(1, 15, 5), 0) end 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) error('Field "%s" is immutable.', key) end, function(key) error('Field "%s" already exists.', key) end importer_mt = {__metatable=false} @@ -105,7 +105,7 @@ function module(name) mutators = {accessor=function(f) set_property(state.metadata, accessors, ACCESSOR, state.property, f) end, mutator=function(f) set_property(state.metadata, mutators, MUTATOR, state.property, f) end} state = { env=env, interface=interface, modifiers=PRIVATE, - metadata = {_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}, + 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, } _modules[name], _state[env], _state[interface], _state[declarator], _state[importer] = state, state, state, state, state diff --git a/tabs/auctions/core.lua b/tabs/auctions/core.lua index 89d7bf6..f2a43f9 100644 --- a/tabs/auctions/core.lua +++ b/tabs/auctions/core.lua @@ -1,6 +1,6 @@ module 'auctions_tab' import 'scan' -auction_records = nil +auction_records = {} function LOAD() create_frames() @@ -25,7 +25,7 @@ function public.scan_auctions() status_bar:update_status(0,0) status_bar:set_text('Scanning auctions...') - auction_records = {} + wipe(auction_records) update_listing() scan.start{ type = 'owner', @@ -58,7 +58,7 @@ end do local scan_id = 0 - local IDLE, SEARCHING, FOUND = {}, {}, {} + local IDLE, SEARCHING, FOUND = t, t, t local state = IDLE local found_index diff --git a/tabs/bids/core.lua b/tabs/bids/core.lua index c9cec10..baadd20 100644 --- a/tabs/bids/core.lua +++ b/tabs/bids/core.lua @@ -1,6 +1,6 @@ module 'bids_tab' import 'scan' -auction_records = nil +auction_records = {} function LOAD() create_frames() @@ -25,7 +25,7 @@ function public.scan_bids() status_bar:update_status(0,0) status_bar:set_text('Scanning auctions...') - auction_records = {} + wipe(auction_records) update_listing() scan.start{ type = 'bidder', diff --git a/tabs/post/core.lua b/tabs/post/core.lua index bdc90a1..100d85e 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -1,13 +1,13 @@ -module 'post_tab' import 'scan' 'post' +module 'post_tab' import 'scan' 'post' 'info' 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'}} existing_auctions = {} -inventory_records = nil -scan_id = 0 -selected_item = nil -refresh = nil +mutable.inventory_records = nil +mutable.scan_id = 0 +mutable.selected_item = nil +mutable.refresh = nil function LOAD() create_frames() @@ -345,7 +345,7 @@ end function unit_vendor_price(item_key) - for slot in inventory do + for slot in info.inventory do local item_info = info.container_item(unpack(slot)) if item_info and item_info.item_key == item_key then @@ -416,7 +416,7 @@ function update_inventory_records() local auction_candidate_map = {} - for slot in inventory do + for slot in info.inventory do local item_info = info.container_item(unpack(slot)) if item_info then diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index 8478638..4ecdaee 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -2,10 +2,10 @@ module 'search_tab' import 'filter_util' function valid_level(str) local level = tonumber(str) - return level and bound(1, 60, level) + return level and bounded(1, 60, level) end -blizzard_query = setmetatable({}, { +blizzard_query = setmetatable(t, { __index = function(_, key) if key == 'name' then return name_input:GetText() @@ -72,14 +72,14 @@ function update_form() end if blizzard_query.exact then - for _, key in {'class', 'subclass', 'slot', 'quality'} do + for key in temp-set 'class' 'subclass' 'slot' 'quality' do _m[key..'_dropdown'].button:Disable() end else class_dropdown.button:Enable() quality_dropdown.button:Enable() end - for _, key in {'min_level', 'max_level'} do + for key in temp-set 'min_level' 'max_level' do if blizzard_query.exact then _m[key..'_input']:Disable() else @@ -92,7 +92,7 @@ function update_form() usable_checkbox:Enable() end - if any({'min_level', 'max_level', 'usable', 'class', 'subclass', 'slot', 'quality'}, function(key) return blizzard_query[key] end) then + if any(temp-list 'min_level' 'max_level' 'usable' 'class' 'subclass' 'slot' 'quality', function(key) return blizzard_query[key] end) then exact_checkbox:Disable() else exact_checkbox:Enable() @@ -119,11 +119,11 @@ function get_filter_builder_query() add(blizzard_query.max_level) add(blizzard_query.usable and 'usable') - for _, class in {blizzard_query.class} do - local classes = {GetAuctionItemClasses()} + for class in present(blizzard_query.class) do + local classes = temp-{GetAuctionItemClasses()} add(strlower(classes[class])) - for _, subclass in {blizzard_query.subclass} do - local subclasses = {GetAuctionItemSubClasses(class)} + for _, subclass in present(blizzard_query.subclass) do + local subclasses = temp-{GetAuctionItemSubClasses(class)} add(strlower(subclasses[subclass])) add(blizzard_query.slot and strlower(_g[blizzard_query.slot])) end @@ -134,7 +134,7 @@ function get_filter_builder_query() add(strlower(_g['ITEM_QUALITY'..quality..'_DESC'])) end - local post_filter_string = filter_util.query_string{blizzard={}, post=post_filter} + local post_filter_string = filter_util.query_string(temp-object :blizzard(tt) :post(post_filter)) add(post_filter_string ~= '' and post_filter_string) return query_string or '' @@ -165,8 +165,8 @@ function clear_form() UIDropDownMenu_ClearAll(slot_dropdown) UIDropDownMenu_ClearAll(quality_dropdown) filter_parameter_input:ClearFocus() - post_filter = {} - filter_builder_state = {selected=0} + wipe(post_filter) + wipe(filter_builder_state).selected = 0 update_filter_display() end @@ -186,7 +186,7 @@ end function public.formatted_post_filter(components) local no_line_break - local stack = {} + local stack = tt local str = '' for i, component in components do @@ -195,7 +195,7 @@ function public.formatted_post_filter(components) elseif i > 1 then str = str..'

' for _=1,getn(stack) do - str = str..color.content.background('----') + str = str..color.content.background '----' end end no_line_break = component[1] == 'operator' and component[2] == 'not' @@ -232,8 +232,8 @@ function data_link(id, str) return '|H'..id..'|h'..str..'|h' end -post_filter = {} -filter_builder_state = {selected = 0} +post_filter = t +filter_builder_state = -object :selected(0) function data_link_click() local button = arg3 @@ -314,12 +314,12 @@ function set_filter_display_offset(x_offset, y_offset) local x_upper_bound = 0 local y_lower_bound = 0 local y_upper_bound = max(0, height - scroll_frame:GetHeight()) - scroll_frame:SetHorizontalScroll(bound(x_lower_bound, x_upper_bound, x_offset)) - scroll_frame:SetVerticalScroll(bound(y_lower_bound, y_upper_bound, y_offset)) + scroll_frame:SetHorizontalScroll(bounded(x_lower_bound, x_upper_bound, x_offset)) + scroll_frame:SetVerticalScroll(bounded(y_lower_bound, y_upper_bound, y_offset)) end function initialize_filter_dropdown() - 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 + for _, filter in temp-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{ text = filter, value = filter, diff --git a/tabs/search/frame.lua b/tabs/search/frame.lua index 49fdbb6..a56a233 100644 --- a/tabs/search/frame.lua +++ b/tabs/search/frame.lua @@ -553,7 +553,7 @@ function create_frames() scroll_frame:EnableMouseWheel(true) scroll_frame:SetScript('OnMouseWheel', function() local child = this:GetScrollChild() - child:SetFont('p', [[Fonts\ARIALN.TTF]], bound(11, 23, select(2, child:GetFont()) + arg1*2)) + child:SetFont('p', [[Fonts\ARIALN.TTF]], bounded(11, 23, select(2, child:GetFont()) + arg1*2)) update_filter_display() end) scroll_frame:RegisterForDrag('LeftButton') diff --git a/tabs/search/results.lua b/tabs/search/results.lua index edb0102..8b5ba7c 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -2,11 +2,11 @@ module 'search_tab' _g.aux_auto_buy_filter = '' -search_scan_id = 0 -auto_buy_validator = nil +mutable.search_scan_id = 0 +mutable.auto_buy_validator = nil do - local searches = {} + local searches = t local search_index = 1 function accessor.current_search() return searches[search_index] end @@ -42,10 +42,7 @@ do while getn(searches) > search_index do tremove(searches) end - local search = { - filter_string = filter_string, - records = {}, - } + local search = -object :filter_string(filter_string) :records(t) tinsert(searches, search) if getn(searches) > 5 then tremove(searches, 1) @@ -56,10 +53,10 @@ do search.status_bar = status_bars[getn(searches)] search.status_bar:update_status(100, 100) - search.status_bar:set_text('') + search.status_bar:set_text '' search.table = tables[getn(searches)] - search.table:SetSort(1,2,3,4,5,6,7,8,9) + search.table:SetSort(1, 2, 3, 4, 5, 6, 7, 8, 9) search.table:Reset() search.table:SetDatabase(search.records) @@ -141,7 +138,7 @@ function start_real_time_scan(query, search, continuation) end local next_page - local new_records = {} + local new_records = t search_scan_id = scan.start{ type = 'list', queries = {query}, @@ -175,7 +172,7 @@ function start_real_time_scan(query, search, continuation) for _, record in new_records do map[record.sniping_signature] = record end - new_records = t + wipe(new_records) for _, record in map do tinsert(new_records, record) end @@ -372,7 +369,7 @@ end do local scan_id = 0 - local IDLE, SEARCHING, FOUND = {}, {}, {} + local IDLE, SEARCHING, FOUND = t, t, t local state = IDLE local found_index @@ -433,9 +430,7 @@ do bid_button:Disable() end - if state == SEARCHING then - return - end + if state == SEARCHING then return end local selection = current_search.table:GetSelection() if not selection then diff --git a/util/core.lua b/util/core.lua index f56b071..915a7c9 100644 --- a/util/core.lua +++ b/util/core.lua @@ -231,36 +231,12 @@ function public.tokenize(str) return tokens end -function public.bound(lower_bound, upper_bound, number) +function public.bounded(lower_bound, upper_bound, number) return max(lower_bound, min(upper_bound, number)) end function public.round(x) return floor(x + 0.5) end -function public.accessor.inventory() - local bag, slot = 0, 0 - return function() - if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then - repeat bag = bag + 1 until GetBagName(bag) or bag > 4 - slot = 1 - else - slot = slot + 1 - end - if bag <= 4 then return {bag, slot}, bag_type(bag) end - end -end - -function public.bag_type(bag) - if bag == 0 then - return 1 - end - for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do - local item_id = info.parse_link(link) - local item_info = info.item(item_id) - return info.item_subclass_index(3, item_info.subclass) - end -end - function public.later(t0, t) return function() return GetTime() - t0 > t end end diff --git a/util/filter.lua b/util/filter.lua index 4267515..1097036 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -1,4 +1,4 @@ -module 'filter_util' import 'info' 'cache' +module 'filter_util' import 'info' function LOAD() import 'cache' @@ -208,7 +208,7 @@ public.filters = { function operator(str) local operator = str == 'not' and {'operator', 'not', 1} - for _, name in {'and', 'or'} do + 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} @@ -264,7 +264,7 @@ do } function blizzard_filter_parser() - return setmetatable({}, mt) + return setmetatable(t, mt) end end @@ -319,14 +319,14 @@ function public.parse_query_string(str) i = i + 1 end - return {blizzard=blizzard_filter_parser(), post=post_filter} + return -object :blizzard(blizzard_filter_parser()) :post(post_filter) end function public.query(query_string) local components, error, suggestions = parse_query_string(query_string) if not components then - return nil, suggestions or {}, error + return nil, suggestions or t, error end local polish_notation_counter = 0 @@ -340,7 +340,7 @@ function public.query(query_string) end if polish_notation_counter > 0 then - local suggestions = {} + local suggestions = t for key in filters do tinsert(suggestions, strlower(key)) end @@ -359,7 +359,7 @@ end function public.queries(query_string) local parts = split(query_string, ';') - local queries = {} + local queries = t for _, str in parts do str = trim(str) local query, _, error = query(str) @@ -374,7 +374,7 @@ function public.queries(query_string) end function suggestions(components) - local suggestions = {} + local suggestions = t if components.blizzard.name and size(components.blizzard) == 1 then tinsert(suggestions, 'exact') end @@ -384,19 +384,19 @@ function suggestions(components) -- classes if not components.blizzard.class then - for _, class in {GetAuctionItemClasses()} do tinsert(suggestions, class) end + for _, class in temp-{GetAuctionItemClasses()} do tinsert(suggestions, class) end end -- subclasses if not components.blizzard.subclass then - for _, subclass in {GetAuctionItemSubClasses(index(components.blizzard.class, 2) or 0)} do + for _, subclass in temp-{GetAuctionItemSubClasses(index(components.blizzard.class, 2) or 0)} do tinsert(suggestions, subclass) end end -- slots if not components.blizzard.slot then - for _, invtype in {GetAuctionInvTypes(index(components.blizzard.class, 2) or 0, index(components.blizzard.subclass, 2) or 0)} do + for _, invtype in temp-{GetAuctionInvTypes(index(components.blizzard.class, 2) or 0, index(components.blizzard.subclass, 2) or 0)} do tinsert(suggestions, _g[invtype]) end end @@ -423,7 +423,7 @@ function public.query_string(components) local query_builder = query_builder() for _, filter in components.blizzard do - query_builder.append((filter[2] or filter[1])) + query_builder.append(filter[2] or filter[1]) end for _, component in components.post do @@ -431,7 +431,7 @@ function public.query_string(components) query_builder.append(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')) elseif component[1] == 'filter' then query_builder.append(component[2]) - for _, parameter in {component[3]} do + for parameter in present(component[3]) do if filter.filters[component[2]].input_type == 'money' then parameter = money.to_string(money.from_string(parameter), nil, true, nil, nil, true) end @@ -496,7 +496,7 @@ end function blizzard_query(components) local filters = components.blizzard - local query = {name=filters.name and filters.name[2]} + local query = -object :name(filters.name and filters.name[2]) local item_info, class_index, subclass_index, slot_index local item_id = cache.item_id(filters.name[2]) @@ -517,7 +517,7 @@ function blizzard_query(components) query.slot = slot_index query.quality = item_info.quality else - for key in set 'min_level' 'max_level' 'class' 'subclass' 'slot' 'usable' 'quality' do + for key in temp-set 'min_level' 'max_level' 'class' 'subclass' 'slot' 'usable' 'quality' do query[key] = index(filters[key], 2) end end @@ -526,7 +526,7 @@ end function validator(components) - local validators = {} + local validators = tt for i, component in components.post do if component[1] == 'filter' then validators[i] = filters[component[2]].validator(parse_parameter(filters[component[2]].input_type, component[3])) @@ -563,21 +563,20 @@ end function public.query_builder() local filter - return { - appended = function(part) + return -object + :appended(function(part) return query_builder(not filter and part or filter..'/'..part) - end, - prepended = function(part) + end) + :prepended(function(part) return query_builder(not filter and part or part..'/'..filter) - end, - append = function(part) + end) + :append(function(part) filter = not filter and part or filter..'/'..part - end, - prepend = function(part) + end) + :prepend(function(part) filter = not filter and part or part..'/'..filter - end, - get = function() + end) + :get(function() return filter or '' - end - } + end) end \ No newline at end of file diff --git a/util/info.lua b/util/info.lua index 47cce91..496eb19 100644 --- a/util/info.lua +++ b/util/info.lua @@ -404,4 +404,27 @@ function public.item_quality_index(item_quality) return i, quality end end +end + +function public.accessor.inventory() + local bag, slot = 0, 0 + return function() + if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then + repeat bag = bag + 1 until GetBagName(bag) or bag > 4 + slot = 1 + else + slot = slot + 1 + end + if bag <= 4 then return {bag, slot}, bag_type(bag) end + end +end + +function public.bag_type(bag) + if bag == 0 then return 1 end + for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do + local item_id = parse_link(link) + local item_info = item(item_id) + log(link, item_id, item_info, item_info.subclass) + return item_subclass_index(3, item_info.subclass) + end end \ No newline at end of file