From 1033d15eae45790271c1fee31a04f670ff136b12 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 24 Oct 2016 20:50:10 +0200 Subject: [PATCH] refactoring --- aux-addon.lua | 36 +++++++++++++------------- color.lua | 4 +-- control.lua | 16 ++++++------ core/cache.lua | 8 +++--- core/disenchant.lua | 6 ++--- core/history.lua | 8 +++--- core/post.lua | 4 +-- core/scan.lua | 4 +-- core/stack.lua | 4 +-- frame.lua | 4 +-- gui/auction_listing.lua | 12 ++++----- gui/core.lua | 46 ++++++++++++++++----------------- gui/item_listing.lua | 6 ++--- gui/listing.lua | 2 +- libs/green_t.lua | 30 +++++++++++----------- libs/module.lua | 4 +-- tabs/auctions/core.lua | 2 +- tabs/bids/core.lua | 2 +- tabs/post/core.lua | 2 +- tabs/search/core.lua | 2 +- tabs/search/results.lua | 2 +- util.lua | 56 ++++++++++++++++++++--------------------- util/completion.lua | 4 +-- util/filter.lua | 16 ++++++------ util/info.lua | 50 ++++++++++++++++++------------------ util/money.lua | 20 +++++++-------- util/persistence.lua | 14 +++++------ util/scan.lua | 4 +-- util/sort.lua | 10 ++++---- 29 files changed, 189 insertions(+), 189 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index 727db22..2779847 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -13,21 +13,21 @@ local scan = require 'aux.core.scan' --aux_account_settings = {} -- TODO clean up the mess of savedvariables --aux_character_settings = {} -public.version = '5.0.0' +M.version = '5.0.0' -function public.set_p(v) +function M.set_p(v) inspect(nil, v) end -function public.print(...) auto[arg] = true +function M.print(...) auto[arg] = true DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. '[aux] ' .. join(map(arg, tostring), ' ')) end local bids_loaded -function public.get_bids_loaded() return bids_loaded end +function M.get_bids_loaded() return bids_loaded end local current_owner_page -function public.get_current_owner_page() return current_owner_page end +function M.get_current_owner_page() return current_owner_page end local event_frame = CreateFrame'Frame' @@ -38,10 +38,10 @@ end ADDON_LOADED = t do local handlers, handlers2 = t, t - function public.set_LOAD(f) + function M.set_LOAD(f) tinsert(handlers, f) end - function public.set_LOAD2(f) + function M.set_LOAD2(f) tinsert(handlers2, f) end event_frame:SetScript('OnEvent', function() @@ -59,14 +59,14 @@ do end tab_info = t -function public.TAB(name) +function M.TAB(name) local tab = T('name', name) local env = getfenv(2) function env.set_OPEN(f) tab.OPEN = f end function env.set_CLOSE(f) tab.CLOSE = f end function env.set_USE_ITEM(f) tab.USE_ITEM = f end function env.set_CLICK_LINK(f) tab.CLICK_LINK = f end - function env.public.get_ACTIVE() return tab == active_tab end + function env.M.get_ACTIVE() return tab == active_tab end tinsert(tab_info, tab) end @@ -98,8 +98,8 @@ function UseContainerItem(...) auto[arg] = true end end -public.orig = setmetatable({[_G]=t}, {__index=function(self, key) return self[_G][key] end}) -function public.hook(...) auto[arg] = true +M.orig = setmetatable({[_G]=t}, {__index=function(self, key) return self[_G][key] end}) +function M.hook(...) auto[arg] = true local name, object, handler if arg.n == 3 then name, object, handler = unpack(arg) @@ -115,8 +115,8 @@ end do local locked - function public.get_bid_in_progress() return locked end - function public.place_bid(type, index, amount, on_success) + function M.get_bid_in_progress() return locked end + function M.place_bid(type, index, amount, on_success) if locked then return end local money = GetMoney() PlaceAuctionBid(type, index, amount) @@ -135,8 +135,8 @@ end do local locked - function public.get_cancel_in_progress() return locked end - function public.cancel_auction(index, on_success) + function M.get_cancel_in_progress() return locked end + function M.cancel_auction(index, on_success) if locked then return end locked = true CancelAuction(index) @@ -150,16 +150,16 @@ do end end -function public.is_player(name, current) +function M.is_player(name, current) local realm = GetCVar'realmName' return not current and index(aux_characters, realm, name) or UnitName'player' == name end -function public.neutral_faction() +function M.neutral_faction() return not UnitFactionGroup'npc' end -function public.min_bid_increment(current_bid) +function M.min_bid_increment(current_bid) return max(1, floor(current_bid / 100) * 5) end diff --git a/color.lua b/color.lua index a32f9ab..f96c09c 100644 --- a/color.lua +++ b/color.lua @@ -49,13 +49,13 @@ do end end } - public.get_color = color_accessor(function(color) + M.get_color = color_accessor(function(color) local r, g, b, a = unpack(color) return setmetatable(A(r/255, g/255, b/255, a), mt) end) end -public.get_inline_color = color_accessor(function(color) +M.get_inline_color = color_accessor(function(color) local r, g, b, a = unpack(color) return format('|c%02X%02X%02X%02X', a, r, g, b) end) diff --git a/control.lua b/control.lua index 1e32b17..95c43ca 100644 --- a/control.lua +++ b/control.lua @@ -5,7 +5,7 @@ local event_frame = CreateFrame'Frame' local listeners, threads = t, t local thread_id -function public.get_thread_id() return thread_id end +function M.get_thread_id() return thread_id end function LOAD() event_frame:SetScript('OnUpdate', UPDATE) @@ -56,19 +56,19 @@ do end end -function public.kill_listener(listener_id) +function M.kill_listener(listener_id) for listener in present(listeners[listener_id]) do listener.killed = true end end -function public.kill_thread(thread_id) +function M.kill_thread(thread_id) for thread in present(threads[thread_id]) do thread.killed = true end end -function public.event_listener(event, cb) +function M.event_listener(event, cb) local listener_id = unique_id listeners[listener_id] = T( 'event', event, @@ -79,18 +79,18 @@ function public.event_listener(event, cb) return listener_id end -function public.on_next_event(event, callback) +function M.on_next_event(event, callback) event_listener(event, function(kill) callback(); kill() end) end -public.thread = vararg-function(arg) +M.thread = vararg-function(arg) local k = tremove(arg, 1) local thread_id = unique_id threads[thread_id] = T('k', papply(k, unpack(arg))) return thread_id end -public.wait = vararg-function(arg) +M.wait = vararg-function(arg) local k = tremove(arg, 1) if type(k) == 'number' then when(function() k = k - 1 return k <= 1 end, unpack(arg)) @@ -99,7 +99,7 @@ public.wait = vararg-function(arg) end end -public.when = vararg-function(arg) +M.when = vararg-function(arg) local c = tremove(arg, 1) local k = tremove(arg, 1) if c() then diff --git a/core/cache.lua b/core/cache.lua index 7c37072..eeb7fd2 100644 --- a/core/cache.lua +++ b/core/cache.lua @@ -77,7 +77,7 @@ function merchant_loaded() return true end -function public.merchant_info(item_id) +function M.merchant_info(item_id) local buy_info if aux_merchant_buy[item_id] then buy_info = persistence.read(merchant_buy_schema, aux_merchant_buy[item_id]) @@ -85,7 +85,7 @@ function public.merchant_info(item_id) return aux_merchant_sell[item_id], buy_info and buy_info.unit_price, buy_info and buy_info.limited end -function public.item_info(item_id) +function M.item_info(item_id) local data_string = aux_items[item_id] if data_string then local cached_data = persistence.read(items_schema, data_string) @@ -103,7 +103,7 @@ function public.item_info(item_id) end end -function public.item_id(item_name) +function M.item_id(item_name) return aux_item_ids[strlower(item_name)] end @@ -189,7 +189,7 @@ function scan_wdb(item_id) end end -function public.populate_wdb(item_id) +function M.populate_wdb(item_id) item_id = item_id or MIN_ITEM_ID if item_id > MAX_ITEM_ID then print'Cache populated.' diff --git a/core/disenchant.lua b/core/disenchant.lua index d421522..4e63773 100644 --- a/core/disenchant.lua +++ b/core/disenchant.lua @@ -38,7 +38,7 @@ do 20725, A('CRYSTAL', '51+') ) - function public.source(item_id) + function M.source(item_id) return unpack(data[item_id] or empty) end end @@ -71,7 +71,7 @@ local WEAPON = S( 'INVTYPE_RANGEDRIGHT' ) -function public.value(slot, quality, level) +function M.value(slot, quality, level) local expectation for _, event in distribution(slot, quality, level) do local value = history.value(event.item_id .. ':' .. 0) @@ -84,7 +84,7 @@ function public.value(slot, quality, level) return expectation end -function public.distribution(slot, quality, level) +function M.distribution(slot, quality, level) if not ARMOR[slot] and not WEAPON[slot] or level == 0 then return t end diff --git a/core/history.lua b/core/history.lua index 1afdcc6..e91fcd0 100644 --- a/core/history.lua +++ b/core/history.lua @@ -51,7 +51,7 @@ function write_record(item_key, record) data[item_key] = persistence.write(history_schema, record) end -function public.process_auction(auction_record) +function M.process_auction(auction_record) local item_record = read_record(auction_record.item_key) local unit_bid_price = ceil(auction_record.bid_price / auction_record.aux_quantity) local unit_buyout_price = ceil(auction_record.buyout_price / auction_record.aux_quantity) @@ -69,12 +69,12 @@ function public.process_auction(auction_record) write_record(auction_record.item_key, item_record) end -function public.price_data(item_key) +function M.price_data(item_key) local item_record = read_record(item_key) return item_record.daily_min_buyout, item_record.daily_max_price, item_record.data_points end -function public.value(item_key) +function M.value(item_key) if not value_cache[item_key] or value_cache[item_key].next_push <= time() then local item_record, value item_record = read_record(item_key) @@ -97,7 +97,7 @@ function public.value(item_key) return value_cache[item_key].value end -function public.market_value(item_key) +function M.market_value(item_key) return calculate_market_value(read_record(item_key)) end diff --git a/core/post.lua b/core/post.lua index a5f9a6d..b750891 100644 --- a/core/post.lua +++ b/core/post.lua @@ -60,7 +60,7 @@ function post_auction(slot, k) end end -function public.stop() +function M.stop() if state then kill_thread(state.thread_id) @@ -75,7 +75,7 @@ function public.stop() end end -function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback) +function M.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, callback) stop() state = { thread_id = thread(process), diff --git a/core/scan.lua b/core/scan.lua index 617998a..5eafd7b 100644 --- a/core/scan.lua +++ b/core/scan.lua @@ -11,7 +11,7 @@ local PAGE_SIZE = 50 do local scan_states = t - function public.start(params) + function M.start(params) for old_state in present(scan_states[params.type]) do abort(old_state.id) end @@ -23,7 +23,7 @@ do return thread_id end - function public.abort(scan_id) + function M.abort(scan_id) local aborted = t for type, state in scan_states do if not scan_id or state.id == scan_id then diff --git a/core/stack.lua b/core/stack.lua index 2479c9f..cfcb3a2 100644 --- a/core/stack.lua +++ b/core/stack.lua @@ -106,7 +106,7 @@ function process() return stop() end -function public.stop() +function M.stop() if state then kill_thread(state.thread_id) local callback, slot = state.callback, state.target_slot @@ -116,7 +116,7 @@ function public.stop() end end -function public.start(item_key, size, callback) +function M.start(item_key, size, callback) stop() state = { thread_id = thread(process), diff --git a/frame.lua b/frame.lua index 1459609..73460ec 100644 --- a/frame.lua +++ b/frame.lua @@ -27,12 +27,12 @@ do frame.content:SetPoint('TOPLEFT', 4, -80) frame.content:SetPoint('BOTTOMRIGHT', -4, 35) frame:Hide() - public.AuxFrame = frame + M.AuxFrame = frame end do tabs = gui.tabs(AuxFrame, 'DOWN') tabs._on_select = on_tab_click - function public.set_tab(id) tabs:select(id) end + function M.set_tab(id) tabs:select(id) end end do local btn = gui.button(AuxFrame) diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua index ab0c7c4..5207973 100644 --- a/gui/auction_listing.lua +++ b/gui/auction_listing.lua @@ -60,7 +60,7 @@ function item_column_init(rt, cell) text:SetPoint('BOTTOMRIGHT', 0, 0) end -public.search_config = { +M.search_config = { { title = 'Item', width = .35, @@ -230,7 +230,7 @@ public.search_config = { }, } -public.auctions_config = { +M.auctions_config = { { title = 'Item', width = .35, @@ -377,7 +377,7 @@ public.auctions_config = { }, } -public.bids_config = { +M.bids_config = { { title = 'Item', width = .35, @@ -548,11 +548,11 @@ function percentage_color(pct) end end -function public.percentage_historical(pct, bid) +function M.percentage_historical(pct, bid) return (bid and inline_color.gray or percentage_color(pct)) .. (pct > 10000 and '>10000' or pct) .. '%' .. FONT_COLOR_CODE_CLOSE end -function public.time_left(code) +function M.time_left(code) return TIME_LEFT_STRINGS[code] end @@ -984,7 +984,7 @@ local methods = { end, } -function public.CreateAuctionResultsTable(parent, config) +function M.CreateAuctionResultsTable(parent, config) RT_COUNT = RT_COUNT + 1 local rt = CreateFrame('Frame', nil, parent) diff --git a/gui/core.lua b/gui/core.lua index a7bd8c4..1b0dded 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -3,9 +3,9 @@ module 'aux.gui' include 'green_t' include 'aux' -public.font = [[Fonts\ARIALN.TTF]] +M.font = [[Fonts\ARIALN.TTF]] -public.font_size = { +M.font_size = { small = 13, medium = 15, large = 18, @@ -87,7 +87,7 @@ end do local id = 1 - function public.get_unique_name() + function M.get_unique_name() id = id + 1 return 'AuxFrame' .. id end @@ -108,7 +108,7 @@ do end return orig() end) - public.menu = vararg-function(arg) + M.menu = vararg-function(arg) structure = perm-arg local x, y = GetCursorPosition() menu:ClearAllPoints() @@ -117,36 +117,36 @@ do end end -function public.set_size(frame, width, height) +function M.set_size(frame, width, height) frame:SetWidth(width) frame:SetHeight(height or width) end -function public.set_frame_style(frame, backdrop_color, border_color, left, right, top, bottom) +function M.set_frame_style(frame, backdrop_color, border_color, left, right, top, bottom) frame:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=1.5, tile=true, insets={left=left, right=right, top=top, bottom=bottom}} frame:SetBackdropColor(backdrop_color()) frame:SetBackdropBorderColor(border_color()) end -function public.set_window_style(frame, left, right, top, bottom) +function M.set_window_style(frame, left, right, top, bottom) set_frame_style(frame, color.window.background, color.window.border, left, right, top, bottom) end -function public.set_panel_style(frame, left, right, top, bottom) +function M.set_panel_style(frame, left, right, top, bottom) set_frame_style(frame, color.panel.background, color.panel.border, left, right, top, bottom) end -function public.set_content_style(frame, left, right, top, bottom) +function M.set_content_style(frame, left, right, top, bottom) set_frame_style(frame, color.content.background, color.content.border, left, right, top, bottom) end -function public.panel(parent) +function M.panel(parent) local panel = CreateFrame('Frame', nil, parent) set_panel_style(panel) return panel end -function public.checkbutton(parent, text_height) +function M.checkbutton(parent, text_height) local button = button(parent, text_height) button.state = false button:SetBackdropColor(color.state.disabled()) @@ -165,7 +165,7 @@ function public.checkbutton(parent, text_height) return button end -function public.button(parent, text_height) +function M.button(parent, text_height) text_height = text_height or font_size.large local button = CreateFrame('Button', nil, parent) set_size(button, 80, 24) @@ -283,7 +283,7 @@ do end end end - function public.tabs(parent, orientation) + function M.tabs(parent, orientation) local self = { _frame = parent, _orientation = orientation, @@ -293,7 +293,7 @@ do end end -function public.editbox(parent) +function M.editbox(parent) local editbox = CreateFrame('EditBox', nil, parent) editbox:SetAutoFocus(false) editbox:SetTextInsets(1.5, 1.5, 3, 3) @@ -370,7 +370,7 @@ function public.editbox(parent) return editbox end -function public.status_bar(parent) +function M.status_bar(parent) local self = CreateFrame('Frame', nil, parent) local level = parent:GetFrameLevel() self:SetFrameLevel(level + 1) @@ -433,7 +433,7 @@ function public.status_bar(parent) return self end -function public.item(parent) +function M.item(parent) local item = CreateFrame('Frame', nil, parent) set_size(item, 260, 40) local btn = CreateFrame('CheckButton', unique_name, item, 'ActionButtonTemplate') @@ -452,14 +452,14 @@ function public.item(parent) return item end -function public.label(parent, size) +function M.label(parent, size) local label = parent:CreateFontString() label:SetFont(font, size or font_size.small) label:SetTextColor(color.label.enabled()) return label end -function public.horizontal_line(parent, y_offset, inverted_color) +function M.horizontal_line(parent, y_offset, inverted_color) local texture = parent:CreateTexture() texture:SetPoint('TOPLEFT', parent, 'TOPLEFT', 2, y_offset) texture:SetPoint('TOPRIGHT', parent, 'TOPRIGHT', -2, y_offset) @@ -472,7 +472,7 @@ function public.horizontal_line(parent, y_offset, inverted_color) return texture end -function public.vertical_line(parent, x_offset, top_offset, bottom_offset, inverted_color) +function M.vertical_line(parent, x_offset, top_offset, bottom_offset, inverted_color) local texture = parent:CreateTexture() texture:SetPoint('TOPLEFT', parent, 'TOPLEFT', x_offset, top_offset or -2) texture:SetPoint('BOTTOMLEFT', parent, 'BOTTOMLEFT', x_offset, bottom_offset or 2) @@ -485,7 +485,7 @@ function public.vertical_line(parent, x_offset, top_offset, bottom_offset, inver return texture end -function public.dropdown(parent) +function M.dropdown(parent) local dropdown = CreateFrame('Frame', unique_name, parent, 'UIDropDownMenuTemplate') set_content_style(dropdown, 0, 0, 4, 4) @@ -509,7 +509,7 @@ function public.dropdown(parent) return dropdown end -function public.slider(parent) +function M.slider(parent) local slider = CreateFrame('Slider', nil, parent) slider:SetOrientation'HORIZONTAL' @@ -545,7 +545,7 @@ function public.slider(parent) return slider end -function public.checkbox(parent) +function M.checkbox(parent) local checkbox = CreateFrame('CheckButton', nil, parent, 'UICheckButtonTemplate') checkbox:SetWidth(16) checkbox:SetHeight(16) @@ -562,7 +562,7 @@ end do local editbox = CreateFrame'EditBox' editbox:SetAutoFocus(false) - function public.clear_focus() + function M.clear_focus() editbox:SetFocus() editbox:ClearFocus() end diff --git a/gui/item_listing.lua b/gui/item_listing.lua index 7149611..871da3b 100644 --- a/gui/item_listing.lua +++ b/gui/item_listing.lua @@ -8,7 +8,7 @@ local gui = require 'aux.gui' local ROW_HEIGHT = 39 -function public.render(item_listing) +function M.render(item_listing) FauxScrollFrame_Update(item_listing.scroll_frame, getn(item_listing.item_records), getn(item_listing.rows), ROW_HEIGHT) local offset = FauxScrollFrame_GetOffset(item_listing.scroll_frame) @@ -41,7 +41,7 @@ function public.render(item_listing) end end -function public.create(parent, on_click, selected) +function M.create(parent, on_click, selected) local content = CreateFrame('Frame', nil, parent) content:SetPoint('TOPLEFT', 0, -51) content:SetPoint('BOTTOMRIGHT', -15, 0) @@ -113,7 +113,7 @@ function public.create(parent, on_click, selected) return item_listing end -function public.populate(item_listing, item_records) +function M.populate(item_listing, item_records) item_listing.item_records = item_records render(item_listing) end diff --git a/gui/listing.lua b/gui/listing.lua index f53085b..ebacca3 100644 --- a/gui/listing.lua +++ b/gui/listing.lua @@ -396,7 +396,7 @@ local methods = { end, } -function public.CreateScrollingTable(parent) +function M.CreateScrollingTable(parent) -- create the base frame ST_COUNT = ST_COUNT + 1 local st = CreateFrame('Frame', 'TSMScrollingTable' .. ST_COUNT, parent) diff --git a/libs/green_t.lua b/libs/green_t.lua index bc45d3b..efab668 100644 --- a/libs/green_t.lua +++ b/libs/green_t.lua @@ -12,7 +12,7 @@ do t.reset, t.reset = nil, 1 setn(t, 0) end - public.wipe = wipe + M.wipe = wipe CreateFrame'Frame':SetScript('OnUpdate', function() for t in auto_release do release(t) end @@ -42,37 +42,37 @@ do overflow_pool[t] = true end end - public.release = release + M.release = release function set_auto_release(v, enable) if type(v) ~= 'table' then return end auto_release[v] = enable and true or nil end - public.set_auto_release = set_auto_release + M.set_auto_release = set_auto_release end -public.get_t = acquire +M.get_t = acquire -function public.get_tt() +function M.get_tt() local t = acquire() set_auto_release(t, true) return t end -public.auto = setmetatable({}, { +M.auto = setmetatable({}, { __metatable = false, __newindex = function(_, k, v) set_auto_release(k, v) end, }) -public.temp = setmetatable({}, { +M.temp = setmetatable({}, { __metatable = false, __sub = function(_, v) set_auto_release(v, true); return v end, }) -public.perm = setmetatable({}, { +M.perm = setmetatable({}, { __metatable = false, __sub = function(_, v) set_auto_release(v, false); return v end, }) -public.init = setmetatable({}, { +M.init = setmetatable({}, { __metatable = false, __newindex = function(_, t, init) wipe(t) @@ -91,10 +91,10 @@ do release(t) end end - public.ret = ret + M.ret = ret end -public.empty = setmetatable({}, { __metatable=false, __newindex=nop }) +M.empty = setmetatable({}, { __metatable=false, __newindex=nop }) local vararg do @@ -137,24 +137,24 @@ do setfenv(chunk, { f=f, setn=setn, acquire=acquire, set_auto_release=set_auto_release }) return chunk() end - public.vararg = setmetatable({}, { + M.vararg = setmetatable({}, { __metatable = false, __sub = function(_, v) return vararg(v) end, }) end -public.A = vararg(function(arg) +M.A = vararg(function(arg) set_auto_release(arg, false) return arg end) -public.S = vararg(function(arg) +M.S = vararg(function(arg) local t = acquire() for _, v in arg do t[v] = true end return t end) -public.T = vararg(function(arg) +M.T = vararg(function(arg) local t = acquire() for i = 1, getn(arg), 2 do t[arg[i]] = arg[i + 1] diff --git a/libs/module.lua b/libs/module.lua index 7c0d125..d5eaac4 100644 --- a/libs/module.lua +++ b/libs/module.lua @@ -37,7 +37,7 @@ function create_module(name) if type(name) ~= 'string' then error('Invalid module name "%s".', name) end local P, environment, interface, public_modifier, accessors, mutators, fields, public_accessors, public_mutators, public_fields environment, interface, public_modifier = {}, {}, setmetatable({}, public_modifier_mt) - accessors = {public=function() return public_modifier end} + accessors = {M=function() return public_modifier end} mutators = setmetatable({_=nop}, {__index=function(_, k) return function(v) define(name, k, v, true) end end}) fields = setmetatable( {_M=environment, _G=_G, include=function(interface) include(name, interface) end, error=error, nop=nop, id=id}, @@ -49,7 +49,7 @@ function create_module(name) setmetatable(environment, proxy_mt(fields, mutators)) setmetatable(interface, proxy_mt(public_fields, public_mutators)) P = { - defined = {_M=true, _G=true, include=true, error=true, nop=true, id=true, public=true, set__=true, require=true}, + defined = {_M=true, _G=true, include=true, error=true, nop=true, id=true, M=true, set__=true, require=true}, fields = fields, accessors = accessors, mutators = mutators, public_fields = public_fields, public_accessors = public_accessors, public_mutators = public_mutators, } diff --git a/tabs/auctions/core.lua b/tabs/auctions/core.lua index 491c28a..a52cd46 100644 --- a/tabs/auctions/core.lua +++ b/tabs/auctions/core.lua @@ -25,7 +25,7 @@ function update_listing() listing:SetDatabase(auction_records) end -function public.scan_auctions() +function M.scan_auctions() status_bar:update_status(0,0) status_bar:set_text'Scanning auctions...' diff --git a/tabs/bids/core.lua b/tabs/bids/core.lua index 031ba94..1ffaf78 100644 --- a/tabs/bids/core.lua +++ b/tabs/bids/core.lua @@ -25,7 +25,7 @@ function update_listing() listing:SetDatabase(auction_records) end -function public.scan_bids() +function M.scan_bids() status_bar:update_status(0,0) status_bar:set_text'Scanning auctions...' diff --git a/tabs/post/core.lua b/tabs/post/core.lua index b13ef9a..17ac466 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -179,7 +179,7 @@ function update_auction_listing() auction_listing:SetData(auction_rows) end -function public.select_item(item_key) +function M.select_item(item_key) for _, inventory_record in filter(copy(inventory_records), function(record) return record.aux_quantity > 0 end) do if inventory_record.key == item_key then update_item(inventory_record) diff --git a/tabs/search/core.lua b/tabs/search/core.lua index 76986b8..53107f5 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -62,7 +62,7 @@ function set_subtab(tab) end end -function public.set_filter(filter_string) +function M.set_filter(filter_string) search_box:SetText(filter_string) end diff --git a/tabs/search/results.lua b/tabs/search/results.lua index 219b6cb..13f0267 100644 --- a/tabs/search/results.lua +++ b/tabs/search/results.lua @@ -293,7 +293,7 @@ function start_search(queries, continuation) } end -function public.execute(resume, real_time) +function M.execute(resume, real_time) if resume then real_time = current_search.real_time diff --git a/util.lua b/util.lua index 11b1e88..7a01a47 100644 --- a/util.lua +++ b/util.lua @@ -19,7 +19,7 @@ do objects[proxy] = setmetatable({}, { __index=classes[self] }) return proxy end - function public.class() + function M.class() local class, interface = {}, {} local private, public, proxy = setmetatable({}, private_mt), setmetatable({}, public_mt), setmetatable({}, proxy_mt) classes[private], classes[public], classes[proxy] = class, class, class @@ -33,14 +33,14 @@ do local __index = function(self, k) return _state[self].handler({ public=self, private=_state[self].state }, k) end - function public.index_function(state, handler) -- TODO rename table-accessor, use predicate to stop + function M.index_function(state, handler) -- TODO rename table-accessor, use predicate to stop local state, self = { handler=handler, state=state }, t _state[self] = state return setmetatable(self, { __metatable=false, __index=__index, state=state }) end end -public.select = vararg-function(arg) +M.select = vararg-function(arg) for _ = 1, arg[1] do tremove(arg, 1) end @@ -51,14 +51,14 @@ public.select = vararg-function(arg) end end -public.join = table.concat +M.join = table.concat -function public.range(arg1, arg2) +function M.range(arg1, arg2) local i, n = arg2 and arg1 or 1, arg2 or arg1 if i <= n then return first, range(i + 1, n) end end -function public.replicate(count, value) +function M.replicate(count, value) if count > 0 then return value, replicate(count - 1, value) end end @@ -69,13 +69,13 @@ do state = nil return temp end - function public.present(v) + function M.present(v) state = v return f end end -public.papply = vararg-function(arg) +M.papply = vararg-function(arg) local f, arg1 = tremove(arg, 1), perm-arg return vararg-function(arg) for i = 1, getn(arg) do @@ -85,47 +85,47 @@ public.papply = vararg-function(arg) end end -public.index = vararg-function(arg) +M.index = vararg-function(arg) local t = tremove(arg, 1) for i = 1, getn(arg) do t = t and t[arg[i]] end return t end -public.huge = 1.8 * 10 ^ 308 +M.huge = 1.8 * 10 ^ 308 -function public.get_modified() +function M.get_modified() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end -function public.copy(t) +function M.copy(t) local copy = _M.t for k, v in t do copy[k] = v end table.setn(copy, getn(t)) return setmetatable(copy, getmetatable(t)) end -function public.size(t) +function M.size(t) local size = 0 for _ in t do size = size + 1 end return size end -function public.key(value, t) +function M.key(value, t) for k, v in t do if v == value then return k end end end -function public.keys(t) +function M.keys(t) local keys = _M.t for k in t do tinsert(keys, k) end return keys end -function public.values(t) +function M.values(t) local values = _M.t for _, v in t do tinsert(values, v) end return values end -function public.eq(t1, t2) +function M.eq(t1, t2) if not t1 or not t2 then return false end for key, value in t1 do if t2[key] ~= value then return false end @@ -136,7 +136,7 @@ function public.eq(t1, t2) return true end -function public.any(t, predicate) +function M.any(t, predicate) for _, v in t do if predicate then if predicate(v) then return true end @@ -147,7 +147,7 @@ function public.any(t, predicate) return false end -function public.all(t, predicate) +function M.all(t, predicate) for _, v in t do if predicate then if not predicate(v) then return false end @@ -158,23 +158,23 @@ function public.all(t, predicate) return true end -function public.filter(t, predicate) +function M.filter(t, predicate) for k, v in t do if not predicate(v, k) then t[k] = nil end end return t end -function public.map(t, f) +function M.map(t, f) for k, v in t do t[k] = f(v, k) end return t end -function public.trim(str) +function M.trim(str) return gsub(str, '^%s*(.-)%s*$', '%1') end -function public.split(str, separator) +function M.split(str, separator) local parts = t while true do local start_index = strfind(str, separator, 1, true) @@ -190,24 +190,24 @@ function public.split(str, separator) end end -function public.tokenize(str) +function M.tokenize(str) local tokens = t for token in string.gfind(str, '%S+') do tinsert(tokens, token) end return tokens end -function public.bounded(lower_bound, upper_bound, number) +function M.bounded(lower_bound, upper_bound, number) return max(lower_bound, min(upper_bound, number)) end -function public.round(x) +function M.round(x) return floor(x + .5) end -function public.later(t0, t) +function M.later(t0, t) return function() return GetTime() - t0 > t end end -function public.signal() local params +function M.signal() local params return function(...) params = arg end, function() return params end end \ No newline at end of file diff --git a/util/completion.lua b/util/completion.lua index 4a5ee44..c05d64b 100644 --- a/util/completion.lua +++ b/util/completion.lua @@ -5,7 +5,7 @@ include 'aux' local filter_util = require 'aux.util.filter' -function public:complete_filter() +function M:complete_filter() if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution return end @@ -27,7 +27,7 @@ function public:complete_filter() end end -function public.complete(options) +function M.complete(options) return function(self) if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution return diff --git a/util/filter.lua b/util/filter.lua index 6ec627b..3d03a25 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -23,7 +23,7 @@ function default_filter(str) } end -public.filters = { +M.filters = { ['utilizable'] = { input_type = '', @@ -283,7 +283,7 @@ function parse_parameter(input_type, str) end end -function public.parse_filter_string(str) +function M.parse_filter_string(str) local filter, post_filter = t, t local blizzard_filter_parser = blizzard_filter_parser() @@ -330,7 +330,7 @@ function public.parse_filter_string(str) return T('components', filter, 'blizzard', blizzard_filter_parser(), 'post', post_filter) end -function public.query(filter_string) +function M.query(filter_string) local filter, error, suggestions = parse_filter_string(filter_string) if not filter then @@ -365,7 +365,7 @@ function public.query(filter_string) }, _M.suggestions(filter) end -function public.queries(filter_string) +function M.queries(filter_string) local parts = split(filter_string, ';') local queries = t for _, str in parts do @@ -426,7 +426,7 @@ function suggestions(filter) return suggestions end -function public.filter_string(components) +function M.filter_string(components) local query_builder = query_builder() for _, component in components do @@ -488,11 +488,11 @@ function prettified_filter_string(filter) end end -function public.quote(name) +function M.quote(name) return '<' .. name .. '>' end -function public.unquote(name) +function M.unquote(name) return select(3, strfind(name, '^<(.*)>$')) or name end @@ -562,7 +562,7 @@ function validator(filter) end end -function public.query_builder() +function M.query_builder() local filter return T( 'append', function(part) diff --git a/util/info.lua b/util/info.lua index feb3695..a780655 100644 --- a/util/info.lua +++ b/util/info.lua @@ -37,12 +37,12 @@ do INVTYPE_RANGEDRIGHT = {18}, INVTYPE_TABARD = {19}, } - function public.inventory_index(slot) + function M.inventory_index(slot) return unpack(inventory_index_map[slot] or tt) end end -function public.container_item(bag, slot) +function M.container_item(bag, slot) for link in present(GetContainerItemLink(bag, slot)) do local item_id, suffix_id, unique_id, enchant_id = parse_link(link) @@ -86,7 +86,7 @@ function public.container_item(bag, slot) end end -function public.auction_sell_item() +function M.auction_sell_item() for name, texture, count, quality, usable, vendor_price in GetAuctionSellItemInfo do return T( 'name', name, @@ -99,7 +99,7 @@ function public.auction_sell_item() end end -function public.auction(index, query_type) +function M.auction(index, query_type) query_type = query_type or 'list' for link in present(GetAuctionItemLink(query_type, index)) do @@ -162,7 +162,7 @@ function public.auction(index, query_type) end end -function public.bid_update(auction_record) +function M.bid_update(auction_record) auction_record.high_bid = auction_record.bid_price auction_record.blizzard_bid = auction_record.bid_price auction_record.min_increment = min_bid_increment(auction_record.bid_price) @@ -173,12 +173,12 @@ function public.bid_update(auction_record) auction_record.search_signature = join(temp-A(auction_record.item_id, auction_record.suffix_id, auction_record.enchant_id, auction_record.start_price, auction_record.buyout_price, auction_record.bid_price, auction_record.aux_quantity, auction_record.duration, 1, aux_ignore_owner and (is_player(auction_record.owner) and 0 or 1) or (auction_record.owner or '?')), ':') end -function public.set_tooltip(itemstring, owner, anchor) +function M.set_tooltip(itemstring, owner, anchor) GameTooltip:SetOwner(owner, anchor) GameTooltip:SetHyperlink(itemstring) end -function public.set_shopping_tooltip(slot) +function M.set_shopping_tooltip(slot) local index1, index2 = inventory_index(slot) local tooltips = tt if index1 then @@ -211,7 +211,7 @@ function public.set_shopping_tooltip(slot) end end -function public.tooltip_match(entry, tooltip) +function M.tooltip_match(entry, tooltip) return any(tooltip, function(line) local left_match = line.left_text and strupper(line.left_text) == strupper(entry) local right_match = line.right_text and strupper(line.right_text) == strupper(entry) @@ -219,7 +219,7 @@ function public.tooltip_match(entry, tooltip) end) end -function public.tooltip_find(pattern, tooltip) +function M.tooltip_find(pattern, tooltip) local count = 0 for _, line in tooltip do if line.left_text and strfind(line.left_text, pattern) then @@ -232,7 +232,7 @@ function public.tooltip_find(pattern, tooltip) return count end -function public.load_tooltip(frame, tooltip) +function M.load_tooltip(frame, tooltip) frame:ClearLines() for _, line in tooltip do if line.right_text then @@ -247,7 +247,7 @@ function public.load_tooltip(frame, tooltip) end end -function public.display_name(item_id, no_brackets, no_color) +function M.display_name(item_id, no_brackets, no_color) for item_info in present(item(item_id)) do local name = item_info.name if not no_brackets then @@ -260,7 +260,7 @@ function public.display_name(item_id, no_brackets, no_color) end end -function public.auctionable(tooltip, quality, lootable) +function M.auctionable(tooltip, quality, lootable) local durability, max_durability = durability(tooltip) return not lootable and (not quality or quality < 6) @@ -271,7 +271,7 @@ function public.auctionable(tooltip, quality, lootable) and not (durability and durability < max_durability) end -function public.tooltip(setter) +function M.tooltip(setter) AuxTooltip:SetOwner(UIParent, 'ANCHOR_NONE') AuxTooltip.money = 0 setter(AuxTooltip) @@ -325,12 +325,12 @@ do -- ... TODO } - function public.max_item_charges(item_id) + function M.max_item_charges(item_id) return data[item_id] end end -function public.durability(tooltip) +function M.durability(tooltip) for _, line in tooltip do local pattern = '^' .. gsub(gsub(DURABILITY_TEMPLATE, '%%d', '(%%d+)'), '%%%d+%$d', '(%%d+)') .. '$' local _, _, left_durability_string, left_max_durability_string = strfind(line.left_text or '', pattern) @@ -343,21 +343,21 @@ function public.durability(tooltip) end end -function public.item_key(link) +function M.item_key(link) local item_id, suffix_id = parse_link(link) return item_id .. ':' .. suffix_id end -function public.parse_link(link) +function M.parse_link(link) local _, _, item_id, enchant_id, suffix_id, unique_id, name = strfind(link, '|c%x%x%x%x%x%x%x%x|Hitem:(%d*):(%d*):(%d*):(%d*)[:0-9]*|h%[(.-)%]|h|r') return tonumber(item_id) or 0, tonumber(suffix_id) or 0, tonumber(unique_id) or 0, tonumber(enchant_id) or 0, name end -function public.itemstring(item_id, suffix_id, unique_id, enchant_id) +function M.itemstring(item_id, suffix_id, unique_id, enchant_id) return 'item:' .. (item_id or 0) .. ':' .. (enchant_id or 0) .. ':' .. (suffix_id or 0) .. ':' .. (unique_id or 0) end -function public.item(item_id, suffix_id) +function M.item(item_id, suffix_id) local itemstring = 'item:' .. (item_id or 0) .. ':0:' .. (suffix_id or 0) .. ':0' local name, itemstring, quality, level, class, subclass, max_stack, slot, texture = GetItemInfo(itemstring) return name and T( @@ -373,7 +373,7 @@ function public.item(item_id, suffix_id) ) or cache.item_info(item_id) end -function public.item_class_index(item_class) +function M.item_class_index(item_class) for i, class in temp-A(GetAuctionItemClasses()) do if strupper(class) == strupper(item_class) then return i, class @@ -381,7 +381,7 @@ function public.item_class_index(item_class) end end -function public.item_subclass_index(class_index, item_subclass) +function M.item_subclass_index(class_index, item_subclass) for i, subclass in temp-A(GetAuctionItemSubClasses(class_index)) do if strupper(subclass) == strupper(item_subclass) then return i, subclass @@ -389,7 +389,7 @@ function public.item_subclass_index(class_index, item_subclass) end end -function public.item_slot_index(class_index, subclass_index, slot_name) +function M.item_slot_index(class_index, subclass_index, slot_name) for i, slot in temp-A(GetAuctionInvTypes(class_index, subclass_index)) do if strupper(_G[slot]) == strupper(slot_name) then return i, _G[slot] @@ -397,7 +397,7 @@ function public.item_slot_index(class_index, subclass_index, slot_name) end end -function public.item_quality_index(item_quality) +function M.item_quality_index(item_quality) for i = 0, 4 do local quality = _G['ITEM_QUALITY' .. i .. '_DESC'] if strupper(item_quality) == strupper(quality) then @@ -406,7 +406,7 @@ function public.item_quality_index(item_quality) end end -function public.get_inventory() +function M.get_inventory() local bag, slot = 0, 0 return function() if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then @@ -419,7 +419,7 @@ function public.get_inventory() end end -function public.bag_type(bag) +function M.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) diff --git a/util/money.lua b/util/money.lua index 4a3b3b6..7e9bdd9 100644 --- a/util/money.lua +++ b/util/money.lua @@ -3,25 +3,25 @@ module 'aux.util.money' include 'green_t' include 'aux' -public.GOLD_TEXT = '|cffffd70ag|r' -public.SILVER_TEXT = '|cffc7c7cfs|r' -public.COPPER_TEXT = '|cffeda55fc|r' +M.GOLD_TEXT = '|cffffd70ag|r' +M.SILVER_TEXT = '|cffc7c7cfs|r' +M.COPPER_TEXT = '|cffeda55fc|r' local COPPER_PER_GOLD = 10000 local COPPER_PER_SILVER = 100 -function public.to_gsc(money) +function M.to_gsc(money) local gold = floor(money / COPPER_PER_GOLD) local silver = floor(mod(money, COPPER_PER_GOLD) / COPPER_PER_SILVER) local copper = mod(money, COPPER_PER_SILVER) return gold, silver, copper end -function public.from_gsc(gold, silver, copper) +function M.from_gsc(gold, silver, copper) return gold * COPPER_PER_GOLD + silver * COPPER_PER_SILVER + copper end -function public.to_string2(money, exact, color) +function M.to_string2(money, exact, color) color = color or FONT_COLOR_CODE_CLOSE local TEXT_NONE = '0' @@ -59,12 +59,12 @@ function public.to_string2(money, exact, color) return str end ---function public.to_string(params) -- TODO +--function M.to_string(params) -- TODO -- local gold, silver, copper = to_gsc(params.copper or 0 + ) -- local settings = set(unpack(arg)) --end -function public.to_string(money, pad, trim, decimal_points, color, no_color) +function M.to_string(money, pad, trim, decimal_points, color, no_color) local is_negative = money < 0 money = abs(money) local gold, silver, copper = to_gsc(money) @@ -115,7 +115,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color) return text end -function public.from_string(value) +function M.from_string(value) local number = tonumber(value) if number and number >= 0 then return number * COPPER_PER_GOLD @@ -139,7 +139,7 @@ function public.from_string(value) return from_gsc(gold or 0, silver or 0, copper or 0) end -function public.format_number(num, pad, decimal_padding, color) +function M.format_number(num, pad, decimal_padding, color) local padding = pad and 2 + (decimal_padding and decimal_padding + 1 or 0) or 0 num = format('%0' .. padding .. '.0' .. (decimal_padding or 0) .. 'f', num) if color then diff --git a/util/persistence.lua b/util/persistence.lua index 4317fda..fbf447b 100644 --- a/util/persistence.lua +++ b/util/persistence.lua @@ -7,7 +7,7 @@ _G.aux_datasets = t do local dataset - function public.get_dataset() + function M.get_dataset() if not dataset then local dataset_key = format('%s|%s', GetCVar'realmName', UnitFactionGroup'player') dataset = aux_datasets[dataset_key] or t @@ -17,7 +17,7 @@ do end end -function public.read(schema, str) +function M.read(schema, str) if schema == 'string' then return str elseif schema == 'boolean' then @@ -33,7 +33,7 @@ function public.read(schema, str) end end -function public.write(schema, obj) +function M.write(schema, obj) if schema == 'string' then return obj or '' elseif schema == 'boolean' then @@ -49,7 +49,7 @@ function public.write(schema, obj) end end -function public.read_list(schema, str) +function M.read_list(schema, str) if str == '' then return t end local separator = schema[2] local element_type = schema[3] @@ -58,7 +58,7 @@ function public.read_list(schema, str) end) end -function public.write_list(schema, list) +function M.write_list(schema, list) local separator = schema[2] local element_type = schema[3] local parts = map(copy(list), function(element) @@ -67,7 +67,7 @@ function public.write_list(schema, list) return join(parts, separator) end -function public.read_record(schema, str) +function M.read_record(schema, str) local separator = schema[2] local record = t local parts = split(str, separator) @@ -78,7 +78,7 @@ function public.read_record(schema, str) return record end -function public.write_record(schema, record) +function M.write_record(schema, record) local separator = schema[2] local parts = tt for i = 3 , getn(schema) do diff --git a/util/scan.lua b/util/scan.lua index 85ec852..f6f25e7 100644 --- a/util/scan.lua +++ b/util/scan.lua @@ -7,7 +7,7 @@ local info = require 'aux.util.info' local filter_util = require 'aux.util.filter' local scan = require 'aux.core.scan' -function public.find(auction_record, status_bar, on_abort, on_failure, on_success) +function M.find(auction_record, status_bar, on_abort, on_failure, on_success) local function test(index) local auction_info = info.auction(index, auction_record.query_type) @@ -72,7 +72,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes } end -function public.item_query(item_id, first_page, last_page) +function M.item_query(item_id, first_page, last_page) for item_info in present(info.item(item_id)) do local query = filter_util.query(item_info.name .. '/exact') query.blizzard_query.first_page = first_page diff --git a/util/sort.lua b/util/sort.lua index 83fff51..07be7e8 100644 --- a/util/sort.lua +++ b/util/sort.lua @@ -3,11 +3,11 @@ module 'aux.util.sort' include 'green_t' include 'aux' -public.EQ = 0 -public.LT = 1 -public.GT = 2 +M.EQ = 0 +M.LT = 1 +M.GT = 2 -function public.compare(a, b, desc) +function M.compare(a, b, desc) if a < b then return desc and GT or LT elseif a > b then @@ -17,7 +17,7 @@ function public.compare(a, b, desc) end end -public.multi_lt = vararg-function(arg) +M.multi_lt = vararg-function(arg) for i = 1, getn(arg), 2 do if arg[i] and arg[i + 1] and arg[i] ~= arg[i + 1] then return arg[i] < arg[i + 1]