From efbae0d433e8c5fd657c58c55b74f371eb8d87d1 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Sat, 5 Nov 2016 08:01:05 +0100 Subject: [PATCH] refactoring --- aux-addon.lua | 18 +++++++++--------- core/cache.lua | 2 +- core/tooltip.lua | 8 ++++---- gui/auction_listing.lua | 2 +- gui/core.lua | 4 ++-- libs/green_t.lua | 38 ++++++++++++++++++-------------------- tabs/post/core.lua | 4 ++-- util.lua | 2 +- 8 files changed, 38 insertions(+), 40 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index fba5240..8109a43 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -19,7 +19,7 @@ function M.set_p(v) inspect(nil, v) end -function M.print(...) auto[arg] = true +function M.print(...) auto_release(arg, true) DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. '[aux] ' .. join(map(arg, tostring), ' ')) end @@ -80,7 +80,7 @@ do end end -function SetItemRef(...) auto[arg] = true +function SetItemRef(...) auto_release(arg, true) if arg[3] ~= 'RightButton' or not index(active_tab, 'CLICK_LINK') or not strfind(arg[1], '^item:%d+') then return orig.SetItemRef(unpack(arg)) end @@ -89,7 +89,7 @@ function SetItemRef(...) auto[arg] = true end end -function UseContainerItem(...) auto[arg] = true +function UseContainerItem(...) auto_release(arg, true) if modified or not index(active_tab, 'USE_ITEM') then return orig.UseContainerItem(unpack(arg)) end @@ -99,7 +99,7 @@ function UseContainerItem(...) auto[arg] = true end M.orig = setmetatable({[_G]=t}, {__index=function(self, key) return self[_G][key] end}) -function M.hook(...) auto[arg] = true +function M.hook(...) auto_release(arg, true) local name, object, handler if arg.n == 3 then name, object, handler = unpack(arg) @@ -185,7 +185,7 @@ end do local last_owner_page_requested - function GetOwnerAuctionItems(...) auto[arg] = true + function GetOwnerAuctionItems(...) auto_release(arg, true) local page = arg[1] last_owner_page_requested = page return orig.GetOwnerAuctionItems(unpack(arg)) @@ -198,7 +198,7 @@ end function ADDON_LOADED.Blizzard_AuctionUI() AuctionFrame:UnregisterEvent'AUCTION_HOUSE_SHOW' AuctionFrame:SetScript('OnHide', nil) - hook('ShowUIPanel', function(...) auto[arg] = true + hook('ShowUIPanel', function(...) auto_release(arg, true) if arg[1] == AuctionFrame then return AuctionFrame:Show() end return orig.ShowUIPanel(unpack(arg)) end) @@ -213,7 +213,7 @@ do return label end function ADDON_LOADED.Blizzard_CraftUI() - hook('CraftFrame_SetSelection', function(...) auto[arg] = true + hook('CraftFrame_SetSelection', function(...) auto_release(arg, true) local ret = temp-A(orig.CraftFrame_SetSelection(unpack(arg))) local id = GetCraftSelectionIndex() local reagent_count = GetCraftNumReagents(id) @@ -240,7 +240,7 @@ do end) end function ADDON_LOADED.Blizzard_TradeSkillUI() - hook('TradeSkillFrame_SetSelection', function(...) auto[arg] = true + hook('TradeSkillFrame_SetSelection', function(...) auto_release(arg, true) local ret = temp-A(orig.TradeSkillFrame_SetSelection(unpack(arg))) local id = GetTradeSkillSelectionIndex() local reagent_count = GetTradeSkillNumReagents(id) @@ -268,7 +268,7 @@ do end end -function AuctionFrameAuctions_OnEvent(...) auto[arg] = true +function AuctionFrameAuctions_OnEvent(...) auto_release(arg, true) if AuctionFrameAuctions:IsVisible() then return orig.AuctionFrameAuctions_OnEvent(unpack(arg)) end diff --git a/core/cache.lua b/core/cache.lua index eeb7fd2..8a1e1e7 100644 --- a/core/cache.lua +++ b/core/cache.lua @@ -146,7 +146,7 @@ function merchant_buy_scan() end function merchant_sell_scan() - for slot in info.inventory do auto[slot] = true + for slot in info.inventory do auto_release(slot, true) local item_info = temp-info.container_item(unpack(slot)) if item_info then aux_merchant_sell[item_info.item_id] = item_info.tooltip_money / item_info.aux_quantity diff --git a/core/tooltip.lua b/core/tooltip.lua index 8c3202f..8dcf02e 100644 --- a/core/tooltip.lua +++ b/core/tooltip.lua @@ -19,7 +19,7 @@ function LOAD() local inside_hook = false for name, f in game_tooltip_hooks do local name, f = name, f - hook(name, GameTooltip, function(...) auto[arg] = true + hook(name, GameTooltip, function(...) auto_release(arg, true) inside_hook = true game_tooltip_money = 0 local ret = temp-A(orig[GameTooltip][name](unpack(arg))) @@ -29,7 +29,7 @@ function LOAD() end) end local orig = GameTooltip:GetScript('OnTooltipAddMoney') - GameTooltip:SetScript('OnTooltipAddMoney', function(...) auto[arg] = true + GameTooltip:SetScript('OnTooltipAddMoney', function(...) auto_release(arg, true) if inside_hook then game_tooltip_money = arg1 else @@ -38,7 +38,7 @@ function LOAD() end) end local orig = SetItemRef - setglobal('SetItemRef', function(...) auto[arg] = true + setglobal('SetItemRef', function(...) auto_release(arg, true) local name, _, quality = GetItemInfo(arg[1]) local ret = A(orig(unpack(arg))) if not IsShiftKeyDown() and not IsControlKeyDown() and name then @@ -216,7 +216,7 @@ end function game_tooltip_hooks:SetAuctionSellItem() local name, _, quantity = GetAuctionSellItemInfo() if name then - for slot in info.inventory do auto[slot] = true + for slot in info.inventory do auto_release(slot, true) local link = GetContainerItemLink(unpack(slot)) if link and select(5, info.parse_link(link)) == name then extend_tooltip(GameTooltip, link, quantity) diff --git a/gui/auction_listing.lua b/gui/auction_listing.lua index 3e17cce..9021d69 100644 --- a/gui/auction_listing.lua +++ b/gui/auction_listing.lua @@ -912,7 +912,7 @@ local methods = { end end, - SetSort = function(self, ...) auto[arg] = true + SetSort = function(self, ...) auto_release(arg, true) for k = 1, arg.n do for i, sort in self.sorts do if sort.index == abs(arg[k]) then diff --git a/gui/core.lua b/gui/core.lua index 1b0dded..b793a7b 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -24,7 +24,7 @@ function LOAD() aux_background:SetTexture(color.content.background()) aux_background:SetAllPoints(DropDownList1Backdrop) blizzard_backdrop = DropDownList1Backdrop:GetBackdrop() - hook('ToggleDropDownMenu', function(...) auto[arg] = true + hook('ToggleDropDownMenu', function(...) auto_release(arg, true) local ret = temp-A(orig.ToggleDropDownMenu(unpack(arg))) local dropdown = _G[arg[4] or ''] or this:GetParent() if strfind(dropdown:GetName() or '', '^AuxFrame%d+$') then @@ -109,7 +109,7 @@ do return orig() end) M.menu = vararg-function(arg) - structure = perm-arg + structure = static-arg local x, y = GetCursorPosition() menu:ClearAllPoints() menu:SetPoint('BOTTOMLEFT', x + 75, y) diff --git a/libs/green_t.lua b/libs/green_t.lua index f88c111..c81dbb4 100644 --- a/libs/green_t.lua +++ b/libs/green_t.lua @@ -2,9 +2,9 @@ library 'green_t' local next, getn, setn, tremove, type, setmetatable = next, getn, table.setn, tremove, type, setmetatable -local wipe, acquire, release, set_auto_release +local wipe, acquire, release, auto_release do - local pool, pool_size, overflow_pool, auto_release = {}, 0, setmetatable({}, {__mode='k'}), {} + local pool, pool_size, overflow_pool, auto_release_queue = {}, 0, setmetatable({}, {__mode='k'}), {} function wipe(t) setmetatable(t, nil) @@ -15,8 +15,8 @@ do M.wipe = wipe CreateFrame'Frame':SetScript('OnUpdate', function() - for t in auto_release do release(t) end - wipe(auto_release) + for t in auto_release_queue do release(t) end + wipe(auto_release_queue) end) function acquire() @@ -35,7 +35,7 @@ do function release(t) wipe(t) - auto_release[t] = nil + auto_release_queue[t] = nil if pool_size < 50 then pool_size = pool_size + 1 pool[pool_size] = t @@ -45,32 +45,30 @@ do end M.release = release - function set_auto_release(v, enable) + function auto_release(v, enable) if type(v) ~= 'table' then return end - auto_release[v] = enable and true or nil + auto_release_queue[v] = enable and true or nil end - M.set_auto_release = set_auto_release + M.auto_release = auto_release end M.get_t = acquire function M.get_tt() local t = acquire() - set_auto_release(t, true) + auto_release(t, true) return t end -M.auto = setmetatable({}, { - __metatable = false, - __newindex = function(_, k, v) set_auto_release(k, v) end, -}) M.temp = setmetatable({}, { __metatable = false, - __sub = function(_, v) set_auto_release(v, true); return v end, + __newindex = nop, + __sub = function(_, v) auto_release(v, true); return v end, }) -M.perm = setmetatable({}, { +M.static = setmetatable({}, { __metatable = false, - __sub = function(_, v) set_auto_release(v, false); return v end, + __newindex = nop, + __sub = function(_, v) auto_release(v, false); return v end, }) do @@ -91,7 +89,7 @@ do local MAXPARAMS = 100 local code = [[ - local f, setn, acquire, set_auto_release = f, setn, acquire, set_auto_release + local f, setn, acquire, auto_release = f, setn, acquire, auto_release return function( ]] for i = 1, MAXPARAMS - 1 do @@ -109,7 +107,7 @@ do code = code .. [[ until true local t = acquire() - set_auto_release(t, true) + auto_release(t, true) setn(t, n) repeat ]] @@ -124,7 +122,7 @@ do function vararg(f) local chunk = loadstring(code) - setfenv(chunk, {f=f, setn=setn, acquire=acquire, set_auto_release=set_auto_release}) + setfenv(chunk, {f=f, setn=setn, acquire=acquire, auto_release=auto_release}) return chunk() end M.vararg = setmetatable({}, { @@ -134,7 +132,7 @@ do end M.A = vararg(function(arg) - set_auto_release(arg, false) + auto_release(arg, false) return arg end) M.S = vararg(function(arg) diff --git a/tabs/post/core.lua b/tabs/post/core.lua index bcc06e6..b426560 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -343,7 +343,7 @@ function quantity_update(max_count) end function unit_vendor_price(item_key) - for slot in info.inventory do auto[slot] = true + for slot in info.inventory do auto_release(slot, true) local item_info = info.container_item(unpack(slot)) if item_info and item_info.item_key == item_key then if info.auctionable(item_info.tooltip, nil, item_info.lootable) then @@ -407,7 +407,7 @@ end function update_inventory_records() local auctionable_map = tt - for slot in info.inventory do auto[slot] = true + for slot in info.inventory do auto_release(slot, true) for item_info in present(info.container_item(unpack(slot))) do local charge_class = item_info.charges or 0 if info.auctionable(item_info.tooltip, nil, item_info.lootable) then diff --git a/util.lua b/util.lua index 7a01a47..4497cc8 100644 --- a/util.lua +++ b/util.lua @@ -76,7 +76,7 @@ do end M.papply = vararg-function(arg) - local f, arg1 = tremove(arg, 1), perm-arg + local f, arg1 = tremove(arg, 1), static-arg return vararg-function(arg) for i = 1, getn(arg) do tinsert(arg1, arg[i])