module/greent refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-09-01 20:40:23 +02:00
parent 03d7dfb204
commit 0d8f5427b2
11 changed files with 268 additions and 255 deletions
+2 -2
View File
@@ -81,7 +81,7 @@ function public.current_owner_page.get() return current_owner_page end
--end
local event_frame = CreateFrame('Frame')
for event in temp-set('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE') do
for event in temp-S('ADDON_LOADED', 'VARIABLES_LOADED', 'PLAYER_LOGIN', 'AUCTION_HOUSE_SHOW', 'AUCTION_HOUSE_CLOSED', 'AUCTION_BIDDER_LIST_UPDATE', 'AUCTION_OWNED_LIST_UPDATE') do
event_frame:RegisterEvent(event)
end
@@ -106,7 +106,7 @@ end
tab_info = t
do
for _, info in temp-list(temp-list('search_tab', 'Search'), temp-list('post_tab', 'Post'), temp-list('auctions_tab', 'Auctions'), temp-list('bids_tab', 'Bids')) do
for _, info in temp-A(temp-A('search_tab', 'Search'), temp-A('post_tab', 'Post'), temp-A('auctions_tab', 'Auctions'), temp-A('bids_tab', 'Bids')) do
local tab = T('name', info[2])
local env = (function() _G.aux(info[1]) return M end)()
function env.private.OPEN.set(f) tab.OPEN = f end
+1 -1
View File
@@ -1,6 +1,6 @@
## Interface: 11200
## Title: aux
## Title: Auction House AddOn
## Description: Auction House AddOn
## SavedVariablesPerCharacter: aux_auto_buy_filter, aux_tooltip_value, aux_tooltip_daily, aux_tooltip_vendor_buy, aux_tooltip_vendor_sell, aux_tooltip_disenchant_value, aux_tooltip_disenchant_distribution, aux_tooltip_disenchant_source
## SavedVariables: aux_datasets, aux_items, aux_item_ids, aux_auctionable_items, aux_merchant_buy, aux_merchant_sell, aux_characters, aux_recent_searches, aux_favorite_searches, aux_ignore_owner, aux_price_per_unit
+51 -51
View File
@@ -4,33 +4,33 @@ UNCOMMON, RARE, EPIC = 2, 3, 4
do
local data = {
[10940] = list('DUST', '1-20'),
[11083] = list('DUST', '21-30'),
[11137] = list('DUST', '31-40'),
[11176] = list('DUST', '41-50'),
[16204] = list('DUST', '51-60'),
[10940] = A('DUST', '1-20'),
[11083] = A('DUST', '21-30'),
[11137] = A('DUST', '31-40'),
[11176] = A('DUST', '41-50'),
[16204] = A('DUST', '51-60'),
[10938] = list('ESSENCE', '1-10'),
[10939] = list('ESSENCE', '11-15'),
[10998] = list('ESSENCE', '16-20'),
[11082] = list('ESSENCE', '21-25'),
[11134] = list('ESSENCE', '26-30'),
[11135] = list('ESSENCE', '31-35'),
[11174] = list('ESSENCE', '36-40'),
[11175] = list('ESSENCE', '41-45'),
[16202] = list('ESSENCE', '46-50'),
[16203] = list('ESSENCE', '51-60'),
[10938] = A('ESSENCE', '1-10'),
[10939] = A('ESSENCE', '11-15'),
[10998] = A('ESSENCE', '16-20'),
[11082] = A('ESSENCE', '21-25'),
[11134] = A('ESSENCE', '26-30'),
[11135] = A('ESSENCE', '31-35'),
[11174] = A('ESSENCE', '36-40'),
[11175] = A('ESSENCE', '41-45'),
[16202] = A('ESSENCE', '46-50'),
[16203] = A('ESSENCE', '51-60'),
[10978] = list('SHARD', '1-20'),
[11084] = list('SHARD', '21-25'),
[11138] = list('SHARD', '26-30'),
[11139] = list('SHARD', '31-35'),
[11177] = list('SHARD', '36-40'),
[11178] = list('SHARD', '41-45'),
[14343] = list('SHARD', '46-50'),
[14344] = list('SHARD', '51-60'),
[10978] = A('SHARD', '1-20'),
[11084] = A('SHARD', '21-25'),
[11138] = A('SHARD', '26-30'),
[11139] = A('SHARD', '31-35'),
[11177] = A('SHARD', '36-40'),
[11178] = A('SHARD', '41-45'),
[14343] = A('SHARD', '46-50'),
[14344] = A('SHARD', '51-60'),
[20725] = list('CRYSTAL', '51+'),
[20725] = A('CRYSTAL', '51+'),
}
function public.source(item_id)
@@ -39,7 +39,7 @@ do
end
function LOAD()
ARMOR = set(
ARMOR = S(
'INVTYPE_HEAD',
'INVTYPE_NECK',
'INVTYPE_SHOULDER',
@@ -56,7 +56,7 @@ function LOAD()
'INVTYPE_CLOAK',
'INVTYPE_HOLDABLE'
)
WEAPON = set(
WEAPON = S(
'INVTYPE_2HWEAPON',
'INVTYPE_WEAPONMAINHAND',
'INVTYPE_WEAPON',
@@ -95,66 +95,66 @@ function public.distribution(slot, quality, level)
if quality == UNCOMMON then
if level <= 10 then
return list(
return A(
T('item_id', 10940, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.8, .2)),
T('item_id', 10938, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .8))
)
elseif level <= 15 then
return list(
return A(
T('item_id', 10940, 'min_quantity', 2, 'max_quantity', 3, 'probability', p(.75, .2)),
T('item_id', 10939, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 20 then
return list(
return A(
T('item_id', 10940, 'min_quantity', 4, 'max_quantity', 6, 'probability', p(.75, .15)),
T('item_id', 10998, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.15, .75)),
T('item_id', 10978, 'min_quantity', 1, 'max_quantity', 1, 'probability', .10)
)
elseif level <= 25 then
return list(
return A(
T('item_id', 11083, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
T('item_id', 11082, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 11084, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 30 then
return list(
return A(
T('item_id', 11083, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .2)),
T('item_id', 11134, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 11138, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 35 then
return list(
return A(
T('item_id', 11137, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
T('item_id', 11135, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 11139, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 40 then
return list(
return A(
T('item_id', 11137, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .2)),
T('item_id', 11174, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 11177, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 45 then
return list(
return A(
T('item_id', 11176, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .2)),
T('item_id', 11175, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 11178, 'min_quantity', 1, 'max_quantity', 1, 'probability', .05)
)
elseif level <= 50 then
return list(
return A(
T('item_id', 11176, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .22)),
T('item_id', 16202, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 14343, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
)
elseif level <= 55 then
return list(
return A(
T('item_id', 16204, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.75, .22)),
T('item_id', 16203, 'min_quantity', 1, 'max_quantity', 2, 'probability', p(.2, .75)),
T('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
)
elseif level <= 60 then
return list(
return A(
T('item_id', 16204, 'min_quantity', 2, 'max_quantity', 5, 'probability', p(.75, .22)),
T('item_id', 16203, 'min_quantity', 2, 'max_quantity', 3, 'probability', p(.2, .75)),
T('item_id', 14344, 'min_quantity', 1, 'max_quantity', 1, 'probability', p(.05, .03))
@@ -162,35 +162,35 @@ function public.distribution(slot, quality, level)
end
elseif quality == RARE then
if level <= 20 then
return list({item_id=10978, min_quantity=1, max_quantity=1, probability=1}) -- TODO
return A({item_id=10978, min_quantity=1, max_quantity=1, probability=1}) -- TODO
elseif level <= 25 then
return list({item_id=11084, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=11084, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 30 then
return list({item_id=11138, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=11138, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 35 then
return list({item_id=11139, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=11139, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 40 then
return list({item_id=11177, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=11177, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 45 then
return list({item_id=11178, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=11178, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 50 then
return list({item_id=14343, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=14343, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 55 then
return list({item_id=14344, min_quantity=1, max_quantity=1, probability=.995}, {item_id=20725, min_quantity=1, max_quantity=1, probability=.005})
return A({item_id=14344, min_quantity=1, max_quantity=1, probability=.995}, {item_id=20725, min_quantity=1, max_quantity=1, probability=.005})
elseif level <= 60 then
return list({item_id=14344, min_quantity=1, max_quantity=1, probability=.995}, {item_id=20725, min_quantity=1, max_quantity=1, probability=.005})
return A({item_id=14344, min_quantity=1, max_quantity=1, probability=.995}, {item_id=20725, min_quantity=1, max_quantity=1, probability=.005})
end
elseif quality == EPIC then
if level <= 40 then
return list({item_id=11177, min_quantity=2, max_quantity=4, probability=1})
return A({item_id=11177, min_quantity=2, max_quantity=4, probability=1})
elseif level <= 45 then
return list({item_id=11178, min_quantity=2, max_quantity=4, probability=1})
return A({item_id=11178, min_quantity=2, max_quantity=4, probability=1})
elseif level <= 50 then
return list({item_id=14343, min_quantity=2, max_quantity=4, probability=1})
return A({item_id=14343, min_quantity=2, max_quantity=4, probability=1})
elseif level <= 55 then
return list({item_id=20725, min_quantity=1, max_quantity=1, probability=1})
return A({item_id=20725, min_quantity=1, max_quantity=1, probability=1})
elseif level <= 60 then
return list({item_id=20725, min_quantity=1, max_quantity=2, probability=1})
return A({item_id=20725, min_quantity=1, max_quantity=2, probability=1})
end
end
return t
+1 -1
View File
@@ -12,7 +12,7 @@ function LOAD()
hook(name, GameTooltip, function(...) temp=arg
inside_hook = true
game_tooltip_money = 0
local ret = temp-ret(orig[GameTooltip][name](unpack(arg)))
local ret = temp-A0(orig[GameTooltip][name](unpack(arg)))
inside_hook = false
f(unpack(arg))
return unpack(ret)
+1 -1
View File
@@ -14,7 +14,7 @@ function LOAD()
aux_background:SetAllPoints(DropDownList1Backdrop)
blizzard_backdrop = DropDownList1Backdrop:GetBackdrop()
hook('ToggleDropDownMenu', function(...) temp=arg
local ret = temp-ret(orig.ToggleDropDownMenu(unpack(arg)))
local ret = temp-A0(orig.ToggleDropDownMenu(unpack(arg)))
local dropdown = _G[arg[4] or ''] or this:GetParent()
if strfind(dropdown:GetName() or '', '^aux_frame%d+$') then
set_aux_dropdown_style(dropdown)
+107 -101
View File
@@ -1,56 +1,24 @@
--__.green_t = function()
if module 'green_t' then return end
local next, setn, setmetatable = next, table.setn, setmetatable
local wipe, recycle, table
local pool, pool_size = {}, 0
local overflow_pool = setmetatable({}, {__mode='k'})
local tmp = {}
CreateFrame('Frame'):SetScript('OnUpdate', function()
for t in tmp do recycle(t) end
wipe(tmp)
end)
do
local t = setmetatable({}, {__metatable=false, __newindex=error})
public.O.get = t
end
function wipe(t) -- like with a cloth or something
local wipe_chunk = [[
for k in t do t[k] = nil end
t.reset = 1
t.reset = nil
t.reset, t.reset = nil, 1
setn(t, 0)
return setmetatable(t, nil)
end
public.wipe = wipe
setmetatable(t, nil)
]]
function recycle(t)
wipe(t)
local recycle_chunk = wipe_chunk..[[
if pool_size < 50 then
pool_size = pool_size + 1
pool[pool_size] = t
else
overflow_pool[t] = true
end
end
public.recycle = recycle
]]
function table()
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 = table
function public.tt.get()
local acquire_chunk = [[
local t
if pool_size > 0 then
t = pool[pool_size]
@@ -63,69 +31,107 @@ function public.tt.get()
t = {}
end
end
tmp[t] = true
return t
]]
pool, pool_size, overflow_pool, tmp = {}, 0, setmetatable({}, {__mode='k'}), {}
public.empty = setmetatable({}, {__metatable=false, __newindex=nop})
do
local f = loadstring([[
local setmetatable, setn = setmetatable, table.setn
return function(t)
]]..wipe_chunk..'return t end') -- like with a cloth or something
setfenv(f, M)
public.wipe = f()
end
do
local function mt(f)
local function apply(self, value)
recycle(self)
return type(value) == 'table' and f(value) or value
end
return {__call=apply, __sub=apply}
end
do
local mt = mt(function(t) tmp[t] = true; return t end)
public.temp
{
get = function() return setmetatable(table(), mt) end,
set = function(t) tmp[t] = true end,
}
end
do
local mt = mt(function(t) tmp[t] = nil; return t end)
public.perm
{
get = function() return setmetatable(table(), mt) end,
set = function(t) tmp[t] = nil end,
}
end
local f = loadstring([[
local setmetatable, setn, pool, pool_size, overflow_pool = setmetatable, table.setn, pool, pool_size, overflow_pool
return function(t)
]]..recycle_chunk..'end')
setfenv(f, M)
public.recycle = f()
end
do
local KEYS, VALUES, RETURN_VALUES, PAIRS = 1, 2, 3, 4
local function insert(type)
local code = 'local setn = table.setn; return function('
for i = 1, 99 do
code = code..'a'..i..','
end
code = code..'overflow) local t = t;'
if type == KEYS then
for i = 1, 99 do
code = code..format('if a%d == nil then return t end; t[a%d] = true;', i, i)
end
elseif type == VALUES then
code = code..'setn(t, 99); if a1 == nil then return t end; t[1] = a1;'
for i = 2, 99 do
code = code..format('if a%d == nil then setn(t, %d); return t end; t[%d] = a%d;', i, i - 1, i, i)
end
elseif type == RETURN_VALUES then
code = code..'setn(t, 99);'
for i = 1, 99 do
code = code..format('t[%d] = a%d;', i, i)
end
elseif type == PAIRS then
for i = 1, 97, 2 do
code = code..format('if a%d == nil then return t end; t[a%d] = a%d;', i, i, i + 1)
end
end
code = code..'return overflow ~= nil and error("Overflow.") or t; end;'
local f = loadstring(code)
setfenv(f, M)
return f
end
public.set.get = insert(KEYS)
public.list.get = insert(VALUES)
public.ret.get = insert(RETURN_VALUES)
public.T.get = insert(PAIRS)
local f = loadstring(format([[
local setmetatable, setn, pool, pool_size, overflow_pool, t = setmetatable, table.setn, pool, pool_size, overflow_pool, tmp
return function() for t in t do %s end %s end
]], recycle_chunk, wipe_chunk))
setfenv(f, M)
CreateFrame'Frame':SetScript('OnUpdate', f())
end
do
local f = loadstring(format([[
local next, pool, pool_size, overflow_pool, tmp = next, pool, pool_size, overflow_pool, tmp
return function() %s; tmp[t] = true; return t end
]], acquire_chunk))
setfenv(f, M)
public.tt.get = f()
end
do local next, pool, pool_size, overflow_pool = next, pool, pool_size, overflow_pool
function public.t.get()
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
end
do local setmetatable, type, tmp = setmetatable, type, tmp
do local f, mt
f = function(_, v) if type(v) == 'table' then tmp[v] = true end return v end
mt = {__call=f, __sub=f}
public.temp {get=function() return setmetatable(tt, mt) end, set=function(t) tmp[t] = true end}
end
do local f, mt
f = function(_, v) if type(v) == 'table' then tmp[v] = nil end return v end
mt = {__call=f, __sub=f}
public.perm {get=function() return setmetatable(tt, mt) end, set=function(t) tmp[t] = nil end}
end
end
do
local SET, ARRAY, ARRAY0, TABLE = 1, 2, 3, 4
local function insert(type)
local chunk = 'local setn, error = table.setn, error; return function('
for i = 1, 99 do chunk = chunk..'a'..i..',' end
chunk = chunk..'overflow)'..acquire_chunk
if type == SET then
for i = 1, 99 do
chunk = chunk..format('if a%d == nil then return t end t[a%d] = true;', i, i)
end
elseif type == ARRAY then
chunk = chunk..'setn(t, 99); if a1 == nil then return t end t[1] = a1;'
for i = 2, 99 do
chunk = chunk..format('if a%d == nil then setn(t, %d); return t end t[%d] = a%d;', i, i - 1, i, i)
end
elseif type == ARRAY0 then
chunk = chunk..'setn(t, 99);'
for i = 1, 99 do
chunk = chunk..format('t[%d] = a%d;', i, i)
end
elseif type == TABLE then
for i = 1, 97, 2 do
chunk = chunk..format('if a%d == nil then return t end t[a%d] = a%d;', i, i, i + 1)
end
end
chunk = chunk..'return overflow ~= nil and error("Overflow.") or t end'
local f = loadstring(chunk)
setfenv(f, M)
return f()
end
public(); S, A, A0, T = insert(SET), insert(ARRAY), insert(ARRAY0), insert(TABLE)
end
--end
+63 -56
View File
@@ -4,19 +4,56 @@ local type, getmetatable, setmetatable, setfenv, unpack, next, _G = type, getmet
local PUBLIC, PRIVATE = 1, 2
local CALL, INDEX, NEWINDEX = 1, 2, 3
local function debug(...) DEFAULT_CHAT_FRAME:AddMessage(' ') for i = 1, arg.n do DEFAULT_CHAT_FRAME:AddMessage(RED_FONT_COLOR_CODE..i..') '..tostring(arg[i])) end DEFAULT_CHAT_FRAME:AddMessage(' ') end
local inspect = setmetatable({}, {
__call=function(_, ...)
DEFAULT_CHAT_FRAME:AddMessage(' ')
for i = 1, arg.n do DEFAULT_CHAT_FRAME:AddMessage(RED_FONT_COLOR_CODE..format('arg%d: %s = %s', i, type(arg[i]), tostring(arg[i]))) end
DEFAULT_CHAT_FRAME:AddMessage(' ')
return unpack(arg)
end,
__sub=function(self, v) self(v); return v end, __pow=function(self, v) self(v); return v end,
})
local function error(msg, ...) return _G.error(format(msg or '', unpack(arg))..'\n'..debugstack(), 0) end
local function import_error() error('Import error.') end
local function declaration_error() error('Declaration error.') end
local function collision_error(key) error('"%s" already exists.', key) end
local function nil_error(key) if key then error('"%s" is nil.', key) else error('Callee is nil') end end
local function nop() end
local function const(v) return function() return v end end
local nop, const = function() end, function(v) return function() return v end end
local function prototype() local eq = const(true)
return setmetatable({__metatable=false, __eq=eq}, {__metatable=false, __eq=eq, __call=function(self, t) return setmetatable(t, self) end})
end
local state = {}
local declarator_mt = {__metatable=false}
local INTERFACE, ENVIRONMENT, DECLARATOR = prototype(), prototype(), prototype()
function INTERFACE:__index(key) self=state[self]
if self.access[key] == PUBLIC then
local getter = self[INDEX][key]
if getter then return getter() else return self[CALL][key] end
end
end
function INTERFACE:__newindex(key, value) self=state[self]
if self.access[key] == PUBLIC then (self[NEWINDEX][key] or nop)(value) end
end
function ENVIRONMENT:__index(key) self=state[self]
local getter = self[INDEX][key]
if getter then return getter() end
return self[CALL][key] or _G[key] or self.declarator[key]
end
function ENVIRONMENT:__newindex(key, value) self=state[self]
if self.access[key] then
local setter = self[NEWINDEX][key] or collision_error(key)
setter(value)
else
self.declarator[key] = value
end
end
do
local ACCESS, EVENT = {public=PUBLIC, private=PRIVATE}, {call=CALL, get=INDEX, set=NEWINDEX}
local function declare(self, access, name, handlers)
@@ -28,88 +65,58 @@ do
self[event][name] = handler
end
end
function declarator_mt:__index(key) self=state[self]
if ACCESS[key] and (not (self.declaration_access or self.declaration_name) or declaration_error()) then
function DECLARATOR:__index(key) self=state[self]; local name, access = self.declaration_name, self.declaration_access
if ACCESS[key] and (not access or declaration_error() and not name or nil_error(name)) then
self.declaration_access = ACCESS[key]
elseif not self.declaration_name or declaration_error() then
self.declaration_name = type(key) == 'string' and key or declaration_error()
elseif not name or nil_error(name) then
self.declaration_name = (type(key) == 'string' or access and declaration_error() or nil_error(name)) and key
end
return self.declarator
end
function declarator_mt:__newindex(key, value) self=state[self]
function DECLARATOR:__newindex(key, value) self=state[self]
local name, event = self.declaration_name, nil
if name then
event = EVENT[key] or error(name)
event = EVENT[key] or nil_error(name)
else
name, event = key, type(value) == 'function' and CALL or INDEX
end
declare(self, self.declaration_access, name, {[event]=value})
self.declaration_access, self.declaration_name = nil, nil
end
function declarator_mt:__call(v) self=state[self]
if self.declaration_name then
if type(v) ~= 'table' or getmetatable(v) ~= nil then declaration_error() end
function DECLARATOR:__call(v) self=state[self]; local name, access = self.declaration_name, self.declaration_access
if name then
if type(v) ~= 'table' or getmetatable(v) ~= nil then (access and declaration_error() or nil_error)(name) end
local f, getter, setter; f, getter, setter, v.call, v.get, v.set = v.call, v.get, v.set, nil, nil, nil
if next(v) or f ~= nil and getter ~= nil then declaration_error() end
declare(self, self.declaration_access, self.declaration_name, {[CALL]=f, [INDEX]=getter, [NEWINDEX]=setter})
elseif self.declaration_access or declaration_error() then
self.default_access = self.declaration_access
if next(v) or f ~= nil and getter ~= nil then (access and declaration_error() or nil_error)(name) end
declare(self, access, name, {[CALL]=f, [INDEX]=getter, [NEWINDEX]=setter})
elseif access or nil_error() then
self.default_access = access
end
self.declaration_access, self.declaration_name = nil, nil
end
end
local env_mt = {__metatable=false}
function env_mt:__index(key) self=state[self]
local getter = self[INDEX][key]
if getter then return getter() end
return self[CALL][key] or _G[key] or self.declarator[key]
end
function env_mt:__newindex(key, value) self=state[self]
if self.access[key] then
local setter = self[NEWINDEX][key] or collision_error(key)
setter(value)
else
self.declarator[key] = value
end
end
local interface_mt = {__metatable=false}
function interface_mt:__index(key) self=state[self]
if self.access[key] == PUBLIC then
local getter = self[INDEX][key]
if getter then return getter() else return self[CALL][key] end
end
end
function interface_mt:__newindex(key, value) self=state[self]
if self.access[key] == PUBLIC then (self[NEWINDEX][key] or nop)(value) end
end
function interface_mt:__eq() return true end
local INTERFACE = setmetatable({}, interface_mt)
local function import(self, ...)
for i = 1, arg.n do
local module = state[arg[i] == INTERFACE and arg[i] or import_error()]
for k, v in module.access do
if v == PUBLIC and not self.access[k] then
self.access[k], self[CALL][k], self[INDEX][k], self[NEWINDEX][k] = PRIVATE, module[CALL][k], module[INDEX][k], module[NEWINDEX][k]
end
local function import(self, interface)
local module = (interface == INTERFACE or import_error()) and state[interface]
for k, v in module.access do
if v == PUBLIC and not self.access[k] then
self.access[k], self[CALL][k], self[INDEX][k], self[NEWINDEX][k] = PRIVATE, module[CALL][k], module[INDEX][k], module[NEWINDEX][k]
end
end
end
function module(name)
if name and _G[name] then return true end
local declarator, env, interface = setmetatable({}, declarator_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
local interface, env, declarator = INTERFACE {}, ENVIRONMENT {}, DECLARATOR {}
local self; self = {
access = {debug=PRIVATE, _=PRIVATE, error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE},
[CALL] = {debug=debug, import=function(...) import(self, unpack(arg)) end, error=error, nop=nop},
access = {inspect=PRIVATE, _=PRIVATE, error=PRIVATE, nop=PRIVATE, _G=PRIVATE, M=PRIVATE, I=PRIVATE, public=PRIVATE, private=PRIVATE},
[CALL] = {inspect=inspect, import=function(interface) import(self, interface) end, error=error, nop=nop},
[INDEX] = {_G=const(_G), M=const(env), I=const(interface), public=function() return declarator.public end, private=function() return declarator.private end},
[NEWINDEX] = {_=nop},
declarator = declarator,
default_access = PRIVATE,
}
state[declarator], state[env], state[interface] = self, self, self
state[interface], state[env], state[declarator] = self, self, self
if name then _G[name] = interface end
setfenv(2, env)
end
+1 -1
View File
@@ -450,7 +450,7 @@ function refresh_entries()
scan_id = scan.start{
type = 'list',
ignore_owner = true,
queries = list(query),
queries = A(query),
on_page_loaded = function(page, total_pages)
status_bar:update_status(100 * (page - 1) / total_pages, 0) -- TODO
status_bar:set_text(format('Scanning Page %d / %d', page, total_pages))
+10 -10
View File
@@ -72,14 +72,14 @@ function update_form()
end
if blizzard_query.exact then
for key in temp-set('class', 'subclass', 'slot', 'quality') do
for key in temp-S('class', 'subclass', 'slot', 'quality') do
M[key..'_dropdown'].button:Disable()
end
else
class_dropdown.button:Enable()
quality_dropdown.button:Enable()
end
for key in temp-set('min_level', 'max_level') do
for key in temp-S('min_level', 'max_level') do
if blizzard_query.exact then
M[key..'_input']:Disable()
else
@@ -92,7 +92,7 @@ function update_form()
usable_checkbox:Enable()
end
if any(list('min_level', 'max_level', 'usable', 'class', 'subclass', 'slot', 'quality'), function(key) return blizzard_query[key] end) then
if any(A('min_level', 'max_level', 'usable', 'class', 'subclass', 'slot', 'quality'), function(key) return blizzard_query[key] end) then
exact_checkbox:Disable()
else
exact_checkbox:Enable()
@@ -120,13 +120,13 @@ function get_filter_builder_query()
add(blizzard_query.usable and 'usable')
for class_index in present(blizzard_query.class) do
local classes = temp-list(GetAuctionItemClasses())
local classes = temp-A(GetAuctionItemClasses())
add(strlower(classes[class_index]))
for subclass_index in present(blizzard_query.subclass) do
local subclasses = temp-list(GetAuctionItemSubClasses(class_index))
local subclasses = temp-A(GetAuctionItemSubClasses(class_index))
add(strlower(subclasses[subclass_index]))
for slot_index in present(blizzard_query.slot) do
local slots = temp-list(GetAuctionInvTypes(class_index, subclass_index))
local slots = temp-A(GetAuctionInvTypes(class_index, subclass_index))
add(strlower(_G[slots[slot_index]]))
end
end
@@ -317,7 +317,7 @@ function set_filter_display_offset(x_offset, y_offset)
end
function initialize_filter_dropdown()
for filter in temp-set('and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity', 'left', 'utilizable', 'discard') do
for filter in temp-S('and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity', 'left', 'utilizable', 'discard') do
UIDropDownMenu_AddButton(T(
'text', filter,
'value', filter,
@@ -348,7 +348,7 @@ function initialize_class_dropdown()
end
end
UIDropDownMenu_AddButton(T('text', ALL, 'value', 0, 'func', on_click))
for i, class in temp-list(GetAuctionItemClasses()) do
for i, class in temp-A(GetAuctionItemClasses()) do
UIDropDownMenu_AddButton(T('text', class, 'value', i, 'func', on_click))
end
end
@@ -365,7 +365,7 @@ function initialize_subclass_dropdown()
local class_index = UIDropDownMenu_GetSelectedValue(class_dropdown)
if class_index and GetAuctionItemSubClasses(class_index) then
UIDropDownMenu_AddButton(T('text', ALL, 'value', 0, 'func', on_click))
for i, subclass in temp-list(GetAuctionItemSubClasses(class_index)) do
for i, subclass in temp-A(GetAuctionItemSubClasses(class_index)) do
UIDropDownMenu_AddButton(T('text', subclass, 'value', i, 'func', on_click))
end
end
@@ -380,7 +380,7 @@ function initialize_slot_dropdown()
local subclass_index = UIDropDownMenu_GetSelectedValue(subclass_dropdown)
if subclass_index and GetAuctionInvTypes(class_index, subclass_index) then
UIDropDownMenu_AddButton(T('text', ALL, 'value', '', 'func', on_click))
for i, slot in temp-list(GetAuctionInvTypes(class_index, subclass_index)) do
for i, slot in temp-A(GetAuctionInvTypes(class_index, subclass_index)) do
UIDropDownMenu_AddButton(T('text', _G[slot], 'value', i, 'func', on_click))
end
end
+26 -26
View File
@@ -41,7 +41,7 @@ public.filters = {
},
['left'] = {
input_type = list('30m', '2h', '8h', '24h'),
input_type = A('30m', '2h', '8h', '24h'),
validator = function(index)
return function(auction_record)
return auction_record.duration == index
@@ -50,7 +50,7 @@ public.filters = {
},
['rarity'] = {
input_type = list('poor', 'common', 'uncommon', 'rare', 'epic'),
input_type = A('poor', 'common', 'uncommon', 'rare', 'epic'),
validator = function(index)
return function(auction_record)
return auction_record.quality == index - 1
@@ -203,11 +203,11 @@ public.filters = {
}
function operator(str)
local operator = str == 'not' and list('operator', 'not', 1)
for name in temp-set('and', 'or') do
local operator = str == 'not' and A('operator', 'not', 1)
for name in temp-S('and', 'or') do
for arity in present(select(3, strfind(str, '^'..name..'(%d*)$'))) do
arity = tonumber(arity)
operator = not (arity and arity < 2) and list('operator', name, arity)
operator = not (arity and arity < 2) and A('operator', name, arity)
end
end
return operator or nil
@@ -223,35 +223,35 @@ do
if self.exact then return end
for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do
if number >= 1 and number <= 60 then
for _, key in temp-list('min_level', 'max_level') do
for _, key in temp-A('min_level', 'max_level') do
if not self[key] then
self[key] = list(str, number)
return list('blizzard', key, str, number)
self[key] = A(str, number)
return A('blizzard', key, str, number)
end
end
end
end
for _, parser in temp-list(
temp-list('class', info.item_class_index),
temp-list('subclass', L(info.item_subclass_index, index(self.class, 2) or 0, _1)),
temp-list('slot', L(info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, _1)),
temp-list('quality', info.item_quality_index)
for _, parser in temp-A(
temp-A('class', info.item_class_index),
temp-A('subclass', L(info.item_subclass_index, index(self.class, 2) or 0, _1)),
temp-A('slot', L(info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, _1)),
temp-A('quality', info.item_quality_index)
) do
if not self[parser[1]] then
tinsert(parser, str)
local index, label = parser[2](select(3, unpack(parser)))
if index then
self[parser[1]] = list(label, index)
return list('blizzard', parser[1], label, index)
self[parser[1]] = A(label, index)
return A('blizzard', parser[1], label, index)
end
end
end
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
self[str] = list(str, 1)
return list('blizzard', str, 1)
self[str] = A(str, 1)
return A('blizzard', str, 1)
elseif i == 1 and strlen(str) <= 63 then
self.name = list(str, unquote(str))
return list('blizzard', 'name', str, unquote(str))
self.name = A(str, unquote(str))
return A('blizzard', 'name', str, unquote(str))
-- return nil, 'The name filter must not be longer than 63 characters' TODO
end
end,
@@ -299,10 +299,10 @@ function public.parse_filter_string(str)
return nil, 'Invalid input for '..parts[i]..'. Expecting: '..input_type
end
end
tinsert(post_filter, list('filter', parts[i], parts[i + 1]))
tinsert(post_filter, A('filter', parts[i], parts[i + 1]))
i = i + 1
else
tinsert(post_filter, list('filter', parts[i]))
tinsert(post_filter, A('filter', parts[i]))
end
tinsert(filter, post_filter[getn(post_filter)])
else
@@ -310,7 +310,7 @@ function public.parse_filter_string(str)
if part then
tinsert(filter, part)
elseif parts[i] ~= '' then
tinsert(post_filter, list('filter', 'tooltip', parts[i]))
tinsert(post_filter, A('filter', 'tooltip', parts[i]))
tinsert(filter, post_filter[getn(post_filter)])
else
return nil, 'Empty modifier'
@@ -384,19 +384,19 @@ function suggestions(filter)
-- classes
if not filter.blizzard.class then
for _, class in temp-list(GetAuctionItemClasses()) do tinsert(suggestions, class) end
for _, class in temp-A(GetAuctionItemClasses()) do tinsert(suggestions, class) end
end
-- subclasses
if not filter.blizzard.subclass then
for _, subclass in temp-list(GetAuctionItemSubClasses(index(filter.blizzard.class, 2) or 0)) do
for _, subclass in temp-A(GetAuctionItemSubClasses(index(filter.blizzard.class, 2) or 0)) do
tinsert(suggestions, subclass)
end
end
-- slots
if not filter.blizzard.slot then
for _, invtype in temp-list(GetAuctionInvTypes(index(filter.blizzard.class, 2) or 0, index(filter.blizzard.subclass, 2) or 0)) do
for _, invtype in temp-A(GetAuctionInvTypes(index(filter.blizzard.class, 2) or 0, index(filter.blizzard.subclass, 2) or 0)) do
tinsert(suggestions, _G[invtype])
end
end
@@ -510,7 +510,7 @@ function blizzard_query(filter)
query.slot = slot_index
query.quality = item_info.quality
else
for key in temp-set('min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality') do
for key in temp-S('min_level', 'max_level', 'class', 'subclass', 'slot', 'usable', 'quality') do
query[key] = index(filters[key], 2)
end
end
+5 -5
View File
@@ -190,7 +190,7 @@ function public.set_shopping_tooltip(slot)
end
if tooltips[1] then
tinsert(tooltips[1], 1, temp-T('left_text', 'Currently Equipped', 'left_color', temp-list(.5, .5, .5)))
tinsert(tooltips[1], 1, temp-T('left_text', 'Currently Equipped', 'left_color', temp-A(.5, .5, .5)))
ShoppingTooltip1:SetOwner(GameTooltip, 'ANCHOR_BOTTOMRIGHT')
load_tooltip(ShoppingTooltip1, tooltips[1])
ShoppingTooltip1:Show()
@@ -198,7 +198,7 @@ function public.set_shopping_tooltip(slot)
end
if tooltips[2] then
tinsert(tooltips[2], 1, temp-T('left_text', 'Currently Equipped', 'left_color', temp-list(.5, .5, .5)))
tinsert(tooltips[2], 1, temp-T('left_text', 'Currently Equipped', 'left_color', temp-A(.5, .5, .5)))
ShoppingTooltip2:SetOwner(ShoppingTooltip1, 'ANCHOR_BOTTOMRIGHT')
load_tooltip(ShoppingTooltip2, tooltips[2])
ShoppingTooltip2:Show()
@@ -371,7 +371,7 @@ function public.item(item_id, suffix_id)
end
function public.item_class_index(item_class)
for i, class in temp-list(GetAuctionItemClasses()) do
for i, class in temp-A(GetAuctionItemClasses()) do
if item_class == nil then error() end
if strupper(class) == strupper(item_class) then
return i, class
@@ -380,7 +380,7 @@ function public.item_class_index(item_class)
end
function public.item_subclass_index(class_index, item_subclass)
for i, subclass in temp-list(GetAuctionItemSubClasses(class_index)) do
for i, subclass in temp-A(GetAuctionItemSubClasses(class_index)) do
if strupper(subclass) == strupper(item_subclass) then
return i, subclass
end
@@ -388,7 +388,7 @@ function public.item_subclass_index(class_index, item_subclass)
end
function public.item_slot_index(class_index, subclass_index, slot_name)
for i, slot in temp-list(GetAuctionInvTypes(class_index, subclass_index)) do
for i, slot in temp-A(GetAuctionInvTypes(class_index, subclass_index)) do
if strupper(_G[slot]) == strupper(slot_name) then
return i, _G[slot]
end