refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-06 19:27:25 +02:00
parent ad4aa1afb2
commit f51d99134e
3 changed files with 33 additions and 14 deletions
+2 -2
View File
@@ -215,7 +215,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-A(orig.CraftFrame_SetSelection(unpack(arg))) local ret = temp-A0(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 +242,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-A(orig.TradeSkillFrame_SetSelection(unpack(arg))) local ret = temp-A0(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 -2
View File
@@ -29,14 +29,13 @@ function LOAD()
end end
local orig = SetItemRef local orig = SetItemRef
setglobal('SetItemRef', function(...) auto[arg] = true setglobal('SetItemRef', function(...) auto[arg] = true
local result = orig(unpack(arg))
local name, _, quality = GetItemInfo(arg[1]) local name, _, quality = GetItemInfo(arg[1])
if not IsShiftKeyDown() and not IsControlKeyDown() and name then if not IsShiftKeyDown() and not IsControlKeyDown() and name then
local color_code = select(4, GetItemQualityColor(quality)) local color_code = select(4, GetItemQualityColor(quality))
local link = color_code .. '|H' .. arg[1] .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE local link = color_code .. '|H' .. arg[1] .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
extend_tooltip(ItemRefTooltip, link, 1) extend_tooltip(ItemRefTooltip, link, 1)
end end
return result return orig(unpack(arg))
end) end)
end end
+30 -10
View File
@@ -112,29 +112,43 @@ function public.pseudo_vararg_function(body, upvals)
end end
do do
local body = [[ local MAXPARAMS = 100
if arg100 ~= nil then error("Vararg overflow.") end
local code = [[
local f, setn, acquire_auto = f, setn, acquire_auto
return function(
]]
for i = 1, MAXPARAMS - 1 do
code = code .. format('a%d,', i)
end
code = code .. [[
overflow)
if overflow ~= nil then error("Vararg overflow.") end
local n local n
repeat repeat
]] ]]
for i = 99, 1, -1 do for i = MAXPARAMS - 1, 1, -1 do
body = body .. format('if a%1$d ~= nil then n = %1$d; break end;', i) code = code .. format('if a%1$d ~= nil then n = %1$d; break end;', i)
end end
body = body .. [[ code = code .. [[
until true until true
local t = acquire_auto() local t = acquire_auto()
setn(t, n) setn(t, n)
repeat repeat
]] ]]
for i = 1, 99 do for i = 1, MAXPARAMS - 1 do
body = body .. format('if %1$d > n then break end; t[%1$d] = a%1$d;', i) code = code .. format('if %1$d > n then break end; t[%1$d] = a%1$d;', i)
end end
body = body .. [[ code = code .. [[
until true until true
return f(t) return f(t)
end
]] ]]
function public.vararg(f) function public.vararg(f)
return pseudo_vararg_function(body, {f=f, error=error, setn=setn, acquire=acquire_auto, release=release}) local chunk = loadstring(code)
setfenv(chunk, {f=f, setn=setn, acquire_auto=acquire_auto})
return chunk()
end end
end end
@@ -168,7 +182,13 @@ do
local mt = {__call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals)} local mt = {__call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals)}
return function() return setmetatable(acquire(), mt) end return function() return setmetatable(acquire(), mt) end
end end
public.S.get = pseudo_table_literal('k') public.S = vararg(function(arg)
local set = acquire()
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.A.get = pseudo_table_literal('v')
public.A0.get = pseudo_table_literal('v0') public.A0.get = pseudo_table_literal('v0')
public.T.get = pseudo_table_literal('kv') public.T.get = pseudo_table_literal('kv')