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
function ADDON_LOADED.Blizzard_CraftUI()
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 reagent_count = GetCraftNumReagents(id)
local total_cost = 0
@@ -242,7 +242,7 @@ do
end
function ADDON_LOADED.Blizzard_TradeSkillUI()
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 reagent_count = GetTradeSkillNumReagents(id)
local total_cost = 0
+1 -2
View File
@@ -29,14 +29,13 @@ function LOAD()
end
local orig = SetItemRef
setglobal('SetItemRef', function(...) auto[arg] = true
local result = orig(unpack(arg))
local name, _, quality = GetItemInfo(arg[1])
if not IsShiftKeyDown() and not IsControlKeyDown() and name then
local color_code = select(4, GetItemQualityColor(quality))
local link = color_code .. '|H' .. arg[1] .. '|h[' .. name .. ']|h' .. FONT_COLOR_CODE_CLOSE
extend_tooltip(ItemRefTooltip, link, 1)
end
return result
return orig(unpack(arg))
end)
end
+30 -10
View File
@@ -112,29 +112,43 @@ function public.pseudo_vararg_function(body, upvals)
end
do
local body = [[
if arg100 ~= nil then error("Vararg overflow.") end
local MAXPARAMS = 100
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
repeat
]]
for i = 99, 1, -1 do
body = body .. format('if a%1$d ~= nil then n = %1$d; break end;', i)
for i = MAXPARAMS - 1, 1, -1 do
code = code .. format('if a%1$d ~= nil then n = %1$d; break end;', i)
end
body = body .. [[
code = code .. [[
until true
local t = acquire_auto()
setn(t, n)
repeat
]]
for i = 1, 99 do
body = body .. format('if %1$d > n then break end; t[%1$d] = a%1$d;', i)
for i = 1, MAXPARAMS - 1 do
code = code .. format('if %1$d > n then break end; t[%1$d] = a%1$d;', i)
end
body = body .. [[
code = code .. [[
until true
return f(t)
end
]]
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
@@ -168,7 +182,13 @@ do
local mt = {__call = pseudo_vararg_function(insert_chunk(mode) .. 'setmetatable(a1, nil); return a1', upvals)}
return function() return setmetatable(acquire(), mt) 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.A0.get = pseudo_table_literal('v0')
public.T.get = pseudo_table_literal('kv')