refactoring
This commit is contained in:
+3
-2
@@ -67,6 +67,7 @@ do
|
|||||||
function env.private.USE_ITEM.set(f) tab.USE_ITEM = f end
|
function env.private.USE_ITEM.set(f) tab.USE_ITEM = f end
|
||||||
function env.private.CLICK_LINK.set(f) tab.CLICK_LINK = f end
|
function env.private.CLICK_LINK.set(f) tab.CLICK_LINK = f end
|
||||||
function env.public.ACTIVE.get() return tab == active_tab end
|
function env.public.ACTIVE.get() return tab == active_tab end
|
||||||
|
p(tab)
|
||||||
tinsert(tab_info, tab)
|
tinsert(tab_info, tab)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -215,7 +216,7 @@ do
|
|||||||
end
|
end
|
||||||
function ADDON_LOADED.Blizzard_CraftUI()
|
function ADDON_LOADED.Blizzard_CraftUI()
|
||||||
hook('CraftFrame_SetSelection', function(...) auto[arg] = true
|
hook('CraftFrame_SetSelection', function(...) auto[arg] = true
|
||||||
local ret = temp-A0(orig.CraftFrame_SetSelection(unpack(arg)))
|
local ret = temp-A(orig.CraftFrame_SetSelection(unpack(arg)))
|
||||||
local id = GetCraftSelectionIndex()
|
local id = GetCraftSelectionIndex()
|
||||||
local reagent_count = GetCraftNumReagents(id)
|
local reagent_count = GetCraftNumReagents(id)
|
||||||
local total_cost = 0
|
local total_cost = 0
|
||||||
@@ -242,7 +243,7 @@ do
|
|||||||
end
|
end
|
||||||
function ADDON_LOADED.Blizzard_TradeSkillUI()
|
function ADDON_LOADED.Blizzard_TradeSkillUI()
|
||||||
hook('TradeSkillFrame_SetSelection', function(...) auto[arg] = true
|
hook('TradeSkillFrame_SetSelection', function(...) auto[arg] = true
|
||||||
local ret = temp-A0(orig.TradeSkillFrame_SetSelection(unpack(arg)))
|
local ret = temp-A(orig.TradeSkillFrame_SetSelection(unpack(arg)))
|
||||||
local id = GetTradeSkillSelectionIndex()
|
local id = GetTradeSkillSelectionIndex()
|
||||||
local reagent_count = GetTradeSkillNumReagents(id)
|
local reagent_count = GetTradeSkillNumReagents(id)
|
||||||
local total_cost = 0
|
local total_cost = 0
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ function LOAD()
|
|||||||
hook(name, GameTooltip, function(...) auto[arg] = true
|
hook(name, GameTooltip, function(...) auto[arg] = true
|
||||||
inside_hook = true
|
inside_hook = true
|
||||||
game_tooltip_money = 0
|
game_tooltip_money = 0
|
||||||
local ret = temp-A0(orig[GameTooltip][name](unpack(arg)))
|
local ret = temp-A(orig[GameTooltip][name](unpack(arg)))
|
||||||
inside_hook = false
|
inside_hook = false
|
||||||
f(unpack(arg))
|
f(unpack(arg))
|
||||||
return unpack(ret)
|
return unpack(ret)
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ function LOAD()
|
|||||||
aux_background:SetAllPoints(DropDownList1Backdrop)
|
aux_background:SetAllPoints(DropDownList1Backdrop)
|
||||||
blizzard_backdrop = DropDownList1Backdrop:GetBackdrop()
|
blizzard_backdrop = DropDownList1Backdrop:GetBackdrop()
|
||||||
hook('ToggleDropDownMenu', function(...) auto[arg] = true
|
hook('ToggleDropDownMenu', function(...) auto[arg] = true
|
||||||
local ret = temp-A0(orig.ToggleDropDownMenu(unpack(arg)))
|
local ret = temp-A(orig.ToggleDropDownMenu(unpack(arg)))
|
||||||
local dropdown = _G[arg[4] or ''] or this:GetParent()
|
local dropdown = _G[arg[4] or ''] or this:GetParent()
|
||||||
if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then
|
if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then
|
||||||
set_aux_dropdown_style(dropdown)
|
set_aux_dropdown_style(dropdown)
|
||||||
|
|||||||
+100
-141
@@ -1,24 +1,79 @@
|
|||||||
green_t = module
|
green_t = module
|
||||||
--setglobal('green_t', green_t and error(nil) or module)
|
--setglobal('green_t', green_t and error(nil) or module)
|
||||||
|
|
||||||
local next, getn, setn, type, setmetatable = next, getn, table.setn, type, setmetatable
|
local next, getn, setn, tremove, type, setmetatable = next, getn, table.setn, tremove, type, setmetatable
|
||||||
local wipe, release, acquire, acquire_auto
|
|
||||||
|
|
||||||
-- TODO mandatory operation table mandate + comply/fulfill functions
|
-- TODO recursive releasing with specified depth, maybe allow setting "release structure" on creation for easier releasing, mandatory operation table mandate + comply/fulfill functions to ensure something is being released?
|
||||||
local pool, pool_size, overflow_pool, auto_release = {}, 0, setmetatable({}, { __mode='k' }), {}
|
|
||||||
|
|
||||||
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
local wipe, acquire, release, set_auto_release
|
||||||
for t in auto_release do release(t) end
|
do
|
||||||
wipe(auto_release)
|
local pool, pool_size, overflow_pool, auto_release = {}, 0, setmetatable({}, { __mode='k' }), {}
|
||||||
end)
|
|
||||||
|
|
||||||
function wipe(t)
|
function wipe(t)
|
||||||
setmetatable(t, nil)
|
setmetatable(t, nil)
|
||||||
for k in t do t[k] = nil end
|
for k in t do t[k] = nil end
|
||||||
t.reset, t.reset = nil, 1
|
t.reset, t.reset = nil, 1
|
||||||
setn(t, 0)
|
setn(t, 0)
|
||||||
|
end
|
||||||
|
public.wipe = wipe
|
||||||
|
|
||||||
|
CreateFrame('Frame'):SetScript('OnUpdate', function()
|
||||||
|
for t in auto_release do release(t) end
|
||||||
|
wipe(auto_release)
|
||||||
|
end)
|
||||||
|
|
||||||
|
function acquire()
|
||||||
|
if pool_size > 0 then
|
||||||
|
pool_size = pool_size - 1
|
||||||
|
return pool[pool_size + 1]
|
||||||
|
end
|
||||||
|
local t = next(overflow_pool)
|
||||||
|
if t then
|
||||||
|
overflow_pool[t] = nil
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
public.acquire = acquire
|
||||||
|
|
||||||
|
function release(t)
|
||||||
|
wipe(t)
|
||||||
|
auto_release[t] = nil
|
||||||
|
if pool_size < 50 then
|
||||||
|
pool_size = pool_size + 1
|
||||||
|
pool[pool_size] = t
|
||||||
|
else
|
||||||
|
overflow_pool[t] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
public.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
|
||||||
end
|
end
|
||||||
public.wipe = wipe
|
|
||||||
|
public.t.get = acquire
|
||||||
|
function public.tt.get()
|
||||||
|
local t = acquire()
|
||||||
|
set_auto_release(t, true)
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
public.auto = setmetatable({}, {
|
||||||
|
__metatable = false,
|
||||||
|
__newindex = function(_, k, v) set_auto_release(k, v) end,
|
||||||
|
})
|
||||||
|
public.temp = setmetatable({}, {
|
||||||
|
__metatable = false,
|
||||||
|
__sub = function(_, v) set_auto_release(v, false); return v end,
|
||||||
|
})
|
||||||
|
public.perm = setmetatable({}, {
|
||||||
|
__metatable = false,
|
||||||
|
__sub = function(_, v) set_auto_release(v, true); return v end,
|
||||||
|
})
|
||||||
|
|
||||||
public.init = setmetatable({}, {
|
public.init = setmetatable({}, {
|
||||||
__metatable = false,
|
__metatable = false,
|
||||||
@@ -31,91 +86,25 @@ public.init = setmetatable({}, {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
function release(t)
|
|
||||||
wipe(t)
|
|
||||||
auto_release[t] = nil
|
|
||||||
if pool_size < 50 then
|
|
||||||
pool_size = pool_size + 1
|
|
||||||
pool[pool_size] = t
|
|
||||||
else
|
|
||||||
overflow_pool[t] = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
public.release = release
|
|
||||||
|
|
||||||
function public.ret(t)
|
|
||||||
if getn(t) > 0 then
|
|
||||||
return tremove(t, 1), ret(t)
|
|
||||||
else
|
|
||||||
release(t)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function acquire()
|
|
||||||
if pool_size > 0 then
|
|
||||||
pool_size = pool_size - 1
|
|
||||||
return pool[pool_size + 1]
|
|
||||||
end
|
|
||||||
local t = next(overflow_pool)
|
|
||||||
if t then
|
|
||||||
overflow_pool[t] = nil
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
public.t.get = acquire
|
|
||||||
|
|
||||||
function acquire_auto()
|
|
||||||
local t = acquire()
|
|
||||||
auto_release[t] = true
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
public.tt.get = acquire_auto
|
|
||||||
|
|
||||||
public.empty = setmetatable({}, { __newindex=nop })
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local function set_auto_release(v, enable)
|
local function ret(t)
|
||||||
if type(v) ~= 'table' then return end
|
if getn(t) > 0 then
|
||||||
auto_release[v] = enable and true or nil
|
return tremove(t, 1), ret(t)
|
||||||
|
else
|
||||||
|
release(t)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
public.auto = setmetatable({}, {
|
public.ret = ret
|
||||||
__metatable = false,
|
|
||||||
__newindex = function(_, k, v) set_auto_release(k, v) end,
|
|
||||||
})
|
|
||||||
public.temp = setmetatable({}, {
|
|
||||||
__metatable = false,
|
|
||||||
__sub = function(_, v) set_auto_release(v, false); return v end,
|
|
||||||
})
|
|
||||||
public.perm = setmetatable({}, {
|
|
||||||
__metatable = false,
|
|
||||||
__sub = function(_, v) set_auto_release(v, true); return v end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function arg_chunk(k, n)
|
public.empty = setmetatable({}, { __metatable=false, __newindex=nop })
|
||||||
k = k or 1
|
|
||||||
n = n or 100
|
|
||||||
local str = k > n and '' or 'a' .. k
|
|
||||||
for i = k + 1, n do str = str .. ',a' .. i end
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
function public.pseudo_vararg_function(body, upvals)
|
|
||||||
local upval_chunk = ''
|
|
||||||
for k in upvals or empty do
|
|
||||||
upval_chunk = upval_chunk .. format('local %1$s = %1$s;', k)
|
|
||||||
end
|
|
||||||
local f = loadstring(format('%s return function(%s) %s end', upval_chunk, arg_chunk(), body)) or error()
|
|
||||||
setfenv(f, upvals or empty)
|
|
||||||
return f()
|
|
||||||
end
|
|
||||||
|
|
||||||
|
local vararg
|
||||||
do
|
do
|
||||||
local MAXPARAMS = 100
|
local MAXPARAMS = 100
|
||||||
|
|
||||||
local code = [[
|
local code = [[
|
||||||
local f, setn, acquire_auto = f, setn, acquire_auto
|
local f, setn, acquire, set_auto_release = f, setn, acquire, set_auto_release
|
||||||
return function(
|
return function(
|
||||||
]]
|
]]
|
||||||
for i = 1, MAXPARAMS - 1 do
|
for i = 1, MAXPARAMS - 1 do
|
||||||
@@ -132,7 +121,8 @@ do
|
|||||||
end
|
end
|
||||||
code = code .. [[
|
code = code .. [[
|
||||||
until true
|
until true
|
||||||
local t = acquire_auto()
|
local t = acquire()
|
||||||
|
set_auto_release(t, true)
|
||||||
setn(t, n)
|
setn(t, n)
|
||||||
repeat
|
repeat
|
||||||
]]
|
]]
|
||||||
@@ -145,60 +135,29 @@ do
|
|||||||
end
|
end
|
||||||
]]
|
]]
|
||||||
|
|
||||||
function public.vararg(f)
|
function vararg(f)
|
||||||
local chunk = loadstring(code)
|
local chunk = loadstring(code)
|
||||||
setfenv(chunk, {f=f, setn=setn, acquire_auto=acquire_auto})
|
setfenv(chunk, {f=f, setn=setn, acquire=acquire, set_auto_release=set_auto_release})
|
||||||
return chunk()
|
return chunk()
|
||||||
end
|
end
|
||||||
|
public.vararg = vararg
|
||||||
end
|
end
|
||||||
|
|
||||||
local function insert_chunk(mode)
|
public.A = vararg(function(arg)
|
||||||
local body = 'repeat '
|
set_auto_release(arg, false)
|
||||||
if mode == 'k' then
|
return arg
|
||||||
for i = 2, 99 do
|
end)
|
||||||
body = body .. format('if a%1$d == nil then break end; a1[a%1$d] = true;', i)
|
public.S = vararg(function(arg)
|
||||||
end
|
local t = acquire()
|
||||||
elseif mode == 'v' then
|
for _, v in arg do
|
||||||
body = body .. 'if a2 == nil then break end; a1[1] = a2;'
|
t[v] = true
|
||||||
for i = 3, 99 do
|
|
||||||
body = body .. format('if a%1$d == nil then setn(a1, %d); break end; a1[%d] = a%1$d;', i, i-2, i-1)
|
|
||||||
end
|
|
||||||
elseif mode == 'v0' then
|
|
||||||
body = body .. 'setn(a1, 98);'
|
|
||||||
for i = 2, 99 do
|
|
||||||
body = body .. format('a1[%d] = a%d;', i-1, i)
|
|
||||||
end
|
|
||||||
elseif mode == 'kv' then
|
|
||||||
for i = 2, 98, 2 do
|
|
||||||
body = body .. format('if a%1$d == nil then break end; a1[a%1$d] = a%d;', i, i+1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return body .. 'if a100 ~= nil then error("Vararg overflow.") end until true;'
|
return t
|
||||||
end
|
end)
|
||||||
|
public.T = vararg(function(arg)
|
||||||
do
|
local t = acquire()
|
||||||
local function pseudo_table_literal(mode)
|
for i = 1, getn(arg), 2 do
|
||||||
local upvals = {setmetatable=setmetatable, setn=setn, error=error}
|
t[arg[i]] = arg[i + 1]
|
||||||
local mt = {__call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals)}
|
|
||||||
return function() return setmetatable(acquire(), mt) end
|
|
||||||
end
|
end
|
||||||
public.S = vararg(function(arg)
|
return t
|
||||||
local set = acquire()
|
end)
|
||||||
for _, v in arg do
|
|
||||||
if v ~= nil then set[v] = true end
|
|
||||||
end
|
|
||||||
return set
|
|
||||||
end)
|
|
||||||
public.A.get = pseudo_table_literal('v')
|
|
||||||
public.A0.get = pseudo_table_literal('v0')
|
|
||||||
public.T.get = pseudo_table_literal('kv')
|
|
||||||
end
|
|
||||||
|
|
||||||
do
|
|
||||||
local body = ''
|
|
||||||
for i = 1, 99 do
|
|
||||||
body = body .. format('if a1 == %d then return %s end;', i, arg_chunk(i+1, 100))
|
|
||||||
end
|
|
||||||
public.select = pseudo_vararg_function(body)
|
|
||||||
end
|
|
||||||
|
|
||||||
@@ -44,6 +44,13 @@ aux 'core'
|
|||||||
-- end
|
-- end
|
||||||
--end
|
--end
|
||||||
|
|
||||||
|
public.select = vararg(function(arg)
|
||||||
|
for _ = 1, arg[1] do
|
||||||
|
tremove(arg, 1)
|
||||||
|
end
|
||||||
|
return unpack(arg)
|
||||||
|
end)
|
||||||
|
|
||||||
public.join = _G.table.concat
|
public.join = _G.table.concat
|
||||||
|
|
||||||
function public.range(arg1, arg2)
|
function public.range(arg1, arg2)
|
||||||
|
|||||||
Reference in New Issue
Block a user