big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-20 12:11:07 +02:00
parent c443509808
commit 9c2598646d
16 changed files with 292 additions and 363 deletions
+2 -2
View File
@@ -41,7 +41,7 @@ do
end
function m.LOAD()
armor = set(
armor = hashset(
'INVTYPE_HEAD',
'INVTYPE_NECK',
'INVTYPE_SHOULDER',
@@ -59,7 +59,7 @@ function m.LOAD()
'INVTYPE_HOLDABLE'
)
weapon = set(
weapon = hashset(
'INVTYPE_2HWEAPON' ,
'INVTYPE_WEAPONMAINHAND',
'INVTYPE_WEAPON',
+3 -3
View File
@@ -9,7 +9,7 @@ do
for _, old_state in {scan_states[params.type]} do
abort(old_state.id)
end
local thread_id = aux.control.thread(aux.C(wait_for_callback, params.on_scan_start, scan))
local thread_id = aux.control.thread(L(wait_for_callback, params.on_scan_start, scan))
scan_states[params.type] = {
id = thread_id,
params = params,
@@ -156,8 +156,8 @@ function scan_page(i)
if call(state.params.auto_buy_validator, auction_info) then
local send_signal, signal_received = signal()
aux.control.when(signal_received, recurse)
aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, aux.C(send_signal, true))
return aux.control.thread(aux.control.when, later(GetTime(), 10), aux.C(send_signal, false))
aux.place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, L(send_signal, true))
return aux.control.thread(aux.control.when, later(GetTime(), 10), L(send_signal, false))
elseif not query.validator or query.validator(auction_info) then
return wait_for_callback(state.params.on_auction, auction_info, function(removed)
if removed then
+1 -1
View File
@@ -73,7 +73,7 @@ function SlashCmdList.AUX(command)
elseif arguments[1] == 'chars' then
local realm = GetCVar 'realmName'
local chars = {}
for name, _ in g.aux_characters[realm] or {} do
for name in g.aux_characters[realm] or {} do
tinsert(chars, name)
end
if getn(chars) > 0 then
+25 -25
View File
@@ -1,17 +1,17 @@
aux.module 'control'
event_frame = CreateFrame('Frame')
event_frame = CreateFrame 'Frame'
listeners = {}
threads = {}
public.thread_id = nil
function m.LOAD()
m.event_frame:SetScript('OnUpdate', m.UPDATE)
m.event_frame:SetScript('OnEvent', m.EVENT)
function LOAD()
event_frame:SetScript('OnUpdate', UPDATE)
event_frame:SetScript('OnEvent', EVENT)
end
function EVENT()
for _, listener in m.listeners do
for _, listener in listeners do
if event == listener.event and not listener.killed then
listener.cb(listener.kill)
end
@@ -19,22 +19,22 @@ function EVENT()
end
function UPDATE()
for _, listener in m.listeners do
if not any(m.listeners, function(l) return not l.killed and l.event == listener.event end) then
m.event_frame:UnregisterEvent(listener.event)
for _, listener in listeners do
if not any(listeners, function(l) return not l.killed and l.event == listener.event end) then
event_frame:UnregisterEvent(listener.event)
end
end
m.listeners = filter(m.listeners, function(l) return not l.killed end)
m.threads = filter(m.threads, function(th) return not th.killed end)
listeners = filter(listeners, function(l) return not l.killed end)
threads = filter(threads, function(th) return not th.killed end)
for thread_id, thread in m.threads do
for id, thread in threads do
if not thread.killed then
local k = thread.k
thread.k = nil
m.thread_id = thread_id
thread_id = id
k()
m.thread_id = nil
thread_id = nil
if not thread.k then
thread.killed = true
end
@@ -44,49 +44,49 @@ end
do
local id = 0
function m.id()
function accessor.id()
id = id + 1
return id
end
end
function public.kill_listener(listener_id)
for _, listener in {m.listeners[listener_id]} do
for _, listener in {listeners[listener_id]} do
listener.killed = true
end
end
function public.kill_thread(thread_id)
for _, thread in {m.threads[thread_id]} do
for _, thread in {threads[thread_id]} do
thread.killed = true
end
end
function public.event_listener(event, cb)
local listener_id = m.id()
m.listeners[listener_id] = {event=event, cb=cb, kill=function(...) if arg.n == 0 or arg[1] then m.kill_listener(listener_id) end end}
m.event_frame:RegisterEvent(event)
local listener_id = id
listeners[listener_id] = {event=event, cb=cb, kill=function(...) if arg.n == 0 or arg[1] then kill_listener(listener_id) end end}
event_frame:RegisterEvent(event)
return listener_id
end
function public.on_next_event(event, callback)
m.event_listener(event, function(kill)
event_listener(event, function(kill)
callback()
kill()
end)
end
function public.thread(k, ...)
local thread_id = m.id()
m.threads[thread_id] = {k = aux.C(k, unpack(arg))}
local thread_id = id
threads[thread_id] = {k = L(k, unpack(arg))}
return thread_id
end
function public.wait(k, ...)
if type(k) == 'number' then
m.when(function() k = k - 1 return k <= 1 end, unpack(arg))
when(function() k = k - 1 return k <= 1 end, unpack(arg))
else
m.threads[m.thread_id].k = aux.C(k, unpack(arg))
threads[thread_id].k = L(k, unpack(arg))
end
end
@@ -94,6 +94,6 @@ function public.when(p, k, ...)
if p() then
return k(unpack(arg))
else
return m.wait(m.when, p, aux.C(k, unpack(arg)))
return wait(when, p, L(k, unpack(arg)))
end
end
+1 -30
View File
@@ -80,7 +80,7 @@ function VARIABLES_LOADED()
btn:SetWidth(65)
btn:SetHeight(24)
btn:SetText 'Close'
btn:SetScript('OnClick', C(frame.Hide, frame))
btn:SetScript('OnClick', L(frame.Hide, frame))
public.close_button = btn
end
do
@@ -305,35 +305,6 @@ do
end
end
public._this = {}
do
local formal_parameters = {}
for i=1,9 do
local key = '_'..i
public[key] = {}
formal_parameters[m[key]] = i
end
local function call(f, arg1, arg2)
local params = {}
for i=1,arg1.n do
if arg1[i] == _this then
tinsert(params, this)
elseif formal_parameters[arg1[i]] then
tinsert(params, arg2[formal_parameters[arg1[i]]])
else
tinsert(params, arg1[i])
end
end
return f(unpack(params))
end
function public.C(f, ...)
local arg1 = arg
return function(...)
return call(f, arg1, arg)
end
end
end
function public.is_player(name, current)
local realm = GetCVar 'realmName'
return not current and index(g.aux_characters, realm, name) or UnitName 'player' == name
+66 -20
View File
@@ -1,30 +1,68 @@
setglobal('aux', aux_module('core'))
import 'util'
public.version = '4.0.0'
public.version = '5.0.0'
module_envs = {}
function public.module(path)
local env
if path == 'core' then
env = getfenv()
elseif module_envs[path] then
env = module_envs[path]
else
local prefix
for name in string.gfind(path, '[%a_][%w_]*') do
local qualified_name = prefix and prefix..'.'..name or name
env = module_envs[qualified_name]
if not env then
(prefix and module_envs[prefix].public or public)[name], env = (function() return aux_module(qualified_name), getfenv() end)()
env.import 'util'
env.LOAD = nil
module_envs[qualified_name] = env
do
local setn = g.table.setn
local table_pool, locked = {}
local function wipe(t) -- like with a cloth or something
for k in t do t[k] = nil end
setn(t, 0)
return t
end
local function release(t)
locked[t] = nil
tinsert(table_pool, t)
end
local function temp()
local t = tremove(table_pool)
t = t and wipe(t) or {}
locked[t] = true
end
public.temp = temp
end
local temp = temp
--do
-- local table_pool = {}
-- onupdate clear tables TODO
-- local setn = g.table.setn
-- public.wipe = wipe
--end
do
local aux_module, getfenv, setfenv, gfind, tinsert = g.aux_module, g.getfenv, g.setfenv, g.string.gfind, g.tinsert
local interface, env = (function() return aux_module('interfaces'), getfenv() end)()
function public.module(path)
local parts = gfind(path, '[%a_][%w_]*')
local name = parts() or ''
for part in parts do
interface[(function() return aux_module(name), getfenv() end)()
name = name..'.'..part
end
local env
if path == 'core' then
env = getfenv()
elseif module_envs[path] then
env = module_envs[path]
else
local prefix
for name in gfind(path, '[%a_][%w_]*') do
local qualified_name = prefix and prefix..'.'..name or name
env = module_envs[qualified_name]
if not env then
(prefix and module_envs[prefix].public or public)[name], env = (function() return aux_module(qualified_name), getfenv() end)()
env.import('core', 'util')
env.mutable.LOAD = nil
module_envs[qualified_name] = env
end
prefix = qualified_name
end
prefix = qualified_name
end
setfenv(2, env)
end
setfenv(2, env)
end
local event_frame = CreateFrame 'Frame'
@@ -49,3 +87,11 @@ event_frame:SetScript('OnEvent', function()
end
end
end)
function public.log(...)
local msg = '[aux]'
for i=1,arg.n do
msg = msg..' '..tostring(arg[i])
end
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg)
end
+25 -37
View File
@@ -1,15 +1,10 @@
local tinsert, setfenv, rawget, rawset, setmetatable, mask, g = tinsert, setfenv, rawget, rawset, setmetatable, bit.band, getfenv(0)
local tinsert, setfenv, rawget, rawset, setmetatable, mask, add, g = tinsert, setfenv, rawget, rawset, setmetatable, bit.band, bit.bor, getfenv(0)
local DECLARED, ACCESSOR, MUTABLE, PUBLIC = 1, 2, 4, 8
local ACCESSOR_KEY, MUTABLE_KEY, PUBLIC_KEY = 'accessor', 'mutable', 'public'
local PROPERTY = {[ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=MUTABLE, [PUBLIC_KEY]=PUBLIC}
local _data, _metadata, _modifier_properties, _imports, _envs, _interfaces = {}, {}, {}, {}, {}, {}
local metadata_mt = {
__index=function() return 0 end,
__newindex=function(self, key, value)
if rawget(self, key) then error('Duplicate key "'..key..'".', 3) end
rawset(self, key, value)
end,
}
local function error(message, ...) g.error(format(message, unpack(arg))..'\n'..debugstack(3, 5, 0), 3) end
local metadata_mt = {__index=function() return 0 end}
local env_mt = {
__metatable = false,
__index = function(self, key)
@@ -25,16 +20,13 @@ local env_mt = {
return interface[key]
end
end
return g[key] or error('No key "'..key..'".', 2)
return g[key] or error('No field "%s".', key)
end
end,
__newindex = function(self, key, value)
local properties = _metadata[self][key]
if properties == 0 then
_metadata[self][key] = DECLARED
-- elseif mask(MUTABLE, properties) == 0 then
-- error('"'..key..'" is immutable.', 2)
end
if mask(DECLARED+MUTABLE, _metadata[self][key]) == DECLARED then error('Field "%s" is immutable.', key) end
_metadata[self][key] = add(DECLARED, properties)
_data[self][key] = value
end,
}
@@ -47,7 +39,7 @@ local interface_mt = {
elseif mask(PUBLIC, properties) ~= 0 then
return value(key)
else
error('No key "'..key..'".', 2)
error('No field "%s".', key)
end
end,
__newindex = function(self, key, value) self[key](value) end,
@@ -56,14 +48,14 @@ local modifier_mt = {
__metatable = false,
__index = function(self, key)
local property = PROPERTY[key]
if not property then error('Unsupported modifier "'..key..'".', 2) end
if mask(property, _modifier_properties[self]) ~= 0 then error('Duplicate modifier "'..key..'".', 2) end
_modifier_properties[self] = _modifier_properties[self] + property
if not property then error('Unknown modifier "%s".', key) end
_modifier_properties[self] = add(property, _modifier_properties[self])
return self
end,
__newindex = function(self, key, value)
_data[self][key] = value
if rawget(_metadata[self], key) then error('Field "%s" already exists.', key) end
_metadata[self][key] = _modifier_properties[self]
_data[self][key] = value
end,
}
local importer_mt = {
@@ -74,22 +66,18 @@ local importer_mt = {
end,
}
function g.aux_module(name)
if _interfaces[name] then error('Duplicate module "'..name..'".', 2) end
local data, metadata, imports, importer, modifier, env, interface, modifier_accessor
modifier, importer, env, interface = setmetatable({}, modifier_mt), setmetatable({}, importer_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
function modifier_accessor(key) _modifier_properties[modifier] = DECLARED+PROPERTY[key] return modifier end
data = {g=g, m=env, import=importer, [ACCESSOR_KEY]=modifier_accessor, [MUTABLE_KEY]=modifier_accessor, [PUBLIC_KEY]=modifier_accessor}
metadata = setmetatable({g=DECLARED, m=DECLARED, import=DECLARED, [ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=ACCESSOR, [PUBLIC_KEY]=ACCESSOR}, metadata_mt)
imports = {}
_envs[name], _interfaces[name] = env, interface
_data[modifier], _data[env], _data[interface] = data, data, data
_metadata[modifier], _metadata[env], _metadata[interface] = metadata, metadata, metadata
_imports[importer], _imports[env] = imports, imports
env.mutable.__ = nil -- TODO
setfenv(2, env)
return interface
if not _envs[name] then
local data, metadata, imports, importer, modifier, env, interface, modifier_accessor
modifier, importer, env, interface = setmetatable({}, modifier_mt), setmetatable({}, importer_mt), setmetatable({}, env_mt), setmetatable({}, interface_mt)
function modifier_accessor(key) _modifier_properties[modifier] = DECLARED+PROPERTY[key] return modifier end
data = {g=g, m=env, import=importer, [ACCESSOR_KEY]=modifier_accessor, [MUTABLE_KEY]=modifier_accessor, [PUBLIC_KEY]=modifier_accessor}
metadata = setmetatable({g=DECLARED, m=DECLARED, import=DECLARED, [ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=ACCESSOR, [PUBLIC_KEY]=ACCESSOR}, metadata_mt)
imports = {}
_envs[name], _interfaces[name] = env, interface
_data[modifier], _data[env], _data[interface] = data, data, data
_metadata[modifier], _metadata[env], _metadata[interface] = metadata, metadata, metadata
_imports[importer], _imports[env] = imports, imports
end
setfenv(2, _envs[name])
return _interfaces[name]
end
+1 -1
View File
@@ -89,7 +89,7 @@ do
m.cancel_button:SetScript('OnClick', function()
if m.test(record)(index) and m.listing:ContainsRecord(record) then
aux.cancel_auction(index, aux.C(m.listing.RemoveAuctionRecord, m.listing, record))
aux.cancel_auction(index, L(m.listing.RemoveAuctionRecord, m.listing, record))
end
end)
m.cancel_button:Enable()
+2 -2
View File
@@ -93,7 +93,7 @@ do
aux.place_bid('bidder', index, record.bid_price, record.bid_price < record.buyout_price and function()
aux.info.bid_update(record)
m.listing:SetDatabase()
end or aux.C(m.listing.RemoveAuctionRecord, m.listing, record))
end or L(m.listing.RemoveAuctionRecord, m.listing, record))
end
end)
m.bid_button:Enable()
@@ -102,7 +102,7 @@ do
if record.buyout_price > 0 then
m.buyout_button:SetScript('OnClick', function()
if m.test(record)(index) and m.listing:ContainsRecord(record) then
aux.place_bid('bidder', index, record.buyout_price, aux.C(m.listing.RemoveAuctionRecord, m.listing, record))
aux.place_bid('bidder', index, record.buyout_price, L(m.listing.RemoveAuctionRecord, m.listing, record))
end
end)
m.buyout_button:Enable()
+3 -3
View File
@@ -364,7 +364,7 @@ function create_frames()
end
end)
editbox.change = update_form
editbox.enter = aux.C(editbox.ClearFocus, editbox)
editbox.enter = L(editbox.ClearFocus, editbox)
local label = aux.gui.label(editbox, aux.gui.config.small_font_size)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText 'Name'
@@ -391,7 +391,7 @@ function create_frames()
max_level_input:SetFocus()
end
end)
editbox.enter = aux.C(editbox.ClearFocus, editbox)
editbox.enter = L(editbox.ClearFocus, editbox)
editbox.change = function()
local valid_level = valid_level(this:GetText())
if tostring(valid_level) ~= this:GetText() then
@@ -416,7 +416,7 @@ function create_frames()
name_input:SetFocus()
end
end)
editbox.enter = aux.C(editbox.ClearFocus, editbox)
editbox.enter = L(editbox.ClearFocus, editbox)
editbox.change = function()
local valid_level = valid_level(this:GetText())
if tostring(valid_level) ~= this:GetText() then
+7 -7
View File
@@ -162,8 +162,8 @@ function start_real_time_scan(query, search, continuation)
if not ignore_page then
if search.auto_buy then
ctrl.suspend()
aux.place_bid('list', auction_record.index, auction_record.buyout_price, aux.C(ctrl.resume, true))
aux.control.thread(aux.control.when, later(GetTime(), 10), aux.C(ctrl.resume, false))
aux.place_bid('list', auction_record.index, auction_record.buyout_price, L(ctrl.resume, true))
aux.control.thread(aux.control.when, later(GetTime(), 10), L(ctrl.resume, false))
else
tinsert(new_records, auction_record)
end
@@ -258,8 +258,8 @@ function start_search(queries, continuation)
on_auction = function(auction_record, ctrl)
if search.auto_buy then
ctrl.suspend()
aux.place_bid('list', auction_record.index, auction_record.buyout_price, aux.C(ctrl.resume, true))
aux.control.thread(aux.control.when, later(GetTime(), 10), aux.C(ctrl.resume, false))
aux.place_bid('list', auction_record.index, auction_record.buyout_price, L(ctrl.resume, true))
aux.control.thread(aux.control.when, later(GetTime(), 10), L(ctrl.resume, false))
elseif getn(search.records) < 1000 then
tinsert(search.records, auction_record)
if getn(search.records) == 1000 then
@@ -335,7 +335,7 @@ function public.execute(resume, real_time)
else
new_search(filter_string)
end
new_recent_search(filter_string, table.concat(map(queries, function(filter) return filter.prettified end), ';'))
new_recent_search(filter_string, join(map(queries, function(filter) return filter.prettified end), ';'))
else
current_search.records = {}
current_search.table:SetDatabase(current_search.records)
@@ -411,7 +411,7 @@ do
aux.place_bid('list', index, record.bid_price, record.bid_price < record.buyout_price and function()
aux.info.bid_update(record)
search.table:SetDatabase()
end or aux.C(search.table.RemoveAuctionRecord, search.table, record))
end or L(search.table.RemoveAuctionRecord, search.table, record))
end
end)
bid_button:Enable()
@@ -420,7 +420,7 @@ do
if record.buyout_price > 0 then
buyout_button:SetScript('OnClick', function()
if test(record)(index) and search.table:ContainsRecord(record) then
aux.place_bid('list', index, record.buyout_price, aux.C(search.table.RemoveAuctionRecord, search.table, record))
aux.place_bid('list', index, record.buyout_price, L(search.table.RemoveAuctionRecord, search.table, record))
end
end)
buyout_button:Enable()
+109 -133
View File
@@ -1,43 +1,98 @@
aux.module 'util'
function public.call(f, ...)
if f then
return f(unpack(arg))
local temp, getn = g.aux.temp, g.getn
function public.copy(t)
local copy = {}
for k, v in t do copy[k] = v end
setn(getn(t))
return copy
end
do
local value, charges
local function setter(n)
return function(v)
assert(charges == 0)
value, charges = v, n
return v
end
end
for i=1,9 do public[join(replicate(i, 'x'))] = setter(i) end
function public.accessor.__()
assert(charges > 0)
charges = charges - 1
return value
end
end
function public.index(t, ...)
for i=1,arg.n do
t = t and t[arg[i]]
do
local state
local function f()
local tmp = state
state = nil
return tmp
end
function public.present(v)
state = v
return f
end
end
do
local formal_parameters = {}
for i=1,9 do
local key = '_'..i
public[key] = {}
formal_parameters[m[key]] = i
end
local function helper(f, arg1, arg2)
local params = {}
for i=1,arg1.n do
if formal_parameters[arg1[i]] then
tinsert(params, arg2[formal_parameters[arg1[i]]])
else
tinsert(params, arg1[i])
end
end
return f(unpack(params))
end
function public.L(f, ...)
if type(f) == 'function' then
local arg1 = arg
return function(...) return helper(f, arg1, arg) end
else
return loadstring 'function(_1,_2,_3,_4,_5,_6,_7,_8,_9)'
end
end
end
function public.call(f, ...)
if f then return f(unpack(arg)) end
end
function public.index(t, ...)
for i=1,arg.n do t = t and t[arg[i]] end
return t
end
public.huge = 1.8*10^308
function public.log(...)
local msg = '[aux]'
for i=1,arg.n do
msg = msg..' '..tostring(arg[i])
end
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE..msg)
end
function public.accessor.modified()
return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown()
end
do
local _state = setmetatable({}, {__mode='kv'})
local __index = function(self, key)
return _state[self].handler({public=self, private=_state[self].state}, key)
end
function public.index_function(state, handler)
local state, self = {handler=handler, state=state}, {}
_state[self] = state
return setmetatable(self, {__metatable=false, __index=__index, state=state})
end
end
--do TODO
-- local _state = setmetatable({}, {__mode='kv'})
-- local __index = function(self, key)
-- return _state[self].handler({public=self, private=_state[self].state}, key)
-- end
-- function public.class(state, handler)
-- local state, self = {handler=handler, state=state}, {}
-- _state[self] = state
-- return setmetatable(self, {__metatable=false, __index=__index, state=state})
-- end
--end
do
local _state = setmetatable({}, {__mode='kv'})
@@ -51,30 +106,9 @@ do
end
end
function public.temp(object)
getfenv(2).__ = object
return object
end
function public.L(body_string)
return loadstring 'function()'
end
function public.present(...)
local called
return function()
if not called then
called = true
return unpack(arg)
end
end
end
function public.expand(array, ...)
local table = {}
for i=1,arg.n do
table[arg[i]] = array[i]
end
for i=1,arg.n do table[arg[i]] = array[i] end
return table
end
@@ -88,103 +122,69 @@ end
function public.size(t)
local size = 0
for _ in t do
size = size + 1
end
for _ in t do size = size + 1 end
return size
end
function public.key(value, t)
for k, v in t do
if v == value then
return k
end
if v == value then return k end
end
end
function public.keys(t)
local ks = {}
for k in t do
tinsert(ks, k)
end
for k in t do tinsert(ks, k) end
return ks
end
function public.values(t)
local vs = {}
for _, v in t do
tinsert(vs, v)
end
for _, v in t do tinsert(vs, v) end
return vs
end
function public.eq(t1, t2)
if not t1 or not t2 then
return false
end
if not t1 or not t2 then return false end
for key, value in t1 do
if t2[key] ~= value then
return false
end
end
for key, value in t2 do
if t1[key] ~= value then
return false
end
end
return true
end
function public.wipe(t)
while getn(t) > 0 do
tremove(t)
end
for k, _ in t do
t[k] = nil
end
end
function public.copy(t)
local copy = {}
for k, v in t do
copy[k] = v
end
return copy
end
function public.any(xs, p)
local holds = false
for _, x in xs do
if p then
holds = holds or p(x)
else
holds = holds or x
if p(x) then return true end
elseif x then
return true
end
end
return holds
return false
end
function public.all(xs, p)
local holds = true
for _, x in xs do
if p then
holds = holds and p(x)
else
holds = holds and x
if not p(x) then
return false
end
elseif not x then
return false
end
end
return holds
return true
end
function public.replicate(count, value)
local array = {}
for i=1,count do
tinsert(array, value)
end
return unpack(array)
return value, replicate(count - 1, value)
end
function public.filter(xs, p)
@@ -199,24 +199,15 @@ end
function public.map(xs, f)
local ys = {}
for k, x in xs do
ys[k] = f(x, k)
end
for k, x in xs do ys[k] = f(x, k) end
return ys
end
do
local mt = {
__call = function(self, key)
return self[key]
end,
}
function public.set(...)
local mt = {__call = function(self, key) return self[key] end}
function public.hashset(...)
local self = {}
for i=1,arg.n do
self[arg[i]] = true
end
for i=1,arg.n do self[arg[i]] = true end
return setmetatable(self, mt)
end
end
@@ -241,11 +232,11 @@ function public.split(str, separator)
end
end
public.join = g.table.concat
function public.tokenize(str)
local tokens = {}
for token in string.gfind(str, '%S+') do
tinsert(tokens, token)
end
for token in string.gfind(str, '%S+') do tinsert(tokens, token) end
return tokens
end
@@ -253,26 +244,18 @@ function public.bound(lower_bound, upper_bound, number)
return max(lower_bound, min(upper_bound, number))
end
function public.round(x)
return floor(x + 0.5)
end
function public.round(x) return floor(x + 0.5) end
function public.accessor.inventory()
local bag, slot = 0, 0
return function()
if not GetBagName(bag) or slot >= GetContainerNumSlots(bag) then
repeat
bag = bag + 1
until GetBagName(bag) or bag > 4
repeat bag = bag + 1 until GetBagName(bag) or bag > 4
slot = 1
else
slot = slot + 1
end
if bag <= 4 then
return {bag, slot}, bag_type(bag)
end
if bag <= 4 then return {bag, slot}, bag_type(bag) end
end
end
@@ -288,17 +271,10 @@ function public.bag_type(bag)
end
function public.later(t0, t)
return function()
return GetTime() - t0 > t
end
return function() return GetTime() - t0 > t end
end
function public.signal()
local params
return function(...)
params = arg
end,
function()
return params
end
return function(...) params = arg end, function() return params end
end
+24 -24
View File
@@ -27,7 +27,7 @@ public.filters = {
['tooltip'] = {
input_type = 'string',
validator = function(str)
return m.default_filter(str).validator()
return default_filter(str).validator()
end,
},
@@ -235,8 +235,8 @@ do
end
for _, parser in {
{'class', aux.info.item_class_index},
{'subclass', aux.C(aux.info.item_subclass_index, index(self.class, 2) or 0, aux._1)},
{'slot', aux.C(aux.info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, aux._1)},
{'subclass', L(aux.info.item_subclass_index, index(self.class, 2) or 0, _1)},
{'slot', L(aux.info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0, _1)},
{'quality', aux.info.item_quality_index},
} do
if not self[parser[1]] then
@@ -250,7 +250,7 @@ do
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
self[str] = {str, 1}
elseif i == 1 and strlen(str) <= 63 then
self.name = {str, m.unquote(str)}
self.name = {str, unquote(str)}
-- return nil, 'The name filter must not be longer than 63 characters'
else
return
@@ -280,17 +280,17 @@ end
function public.parse_query_string(str)
local post_filter = {}
local blizzard_filter_parser = m.blizzard_filter_parser()
local blizzard_filter_parser = blizzard_filter_parser()
local parts = map(split(str, '/'), function(part) return strlower(trim(part)) end)
local i = 1
while parts[i] do
if temp(m.operator(parts[i])) then
if x(operator(parts[i])) then
tinsert(post_filter, __)
elseif temp(m.filters[parts[i]]) then
elseif x(filters[parts[i]]) then
local input_type = __.input_type
if input_type ~= '' then
if not parts[i + 1] or not m.parse_parameter(input_type, parts[i + 1]) then
if not parts[i + 1] or not parse_parameter(input_type, parts[i + 1]) then
if parts[i] == 'item' then
return nil, 'Invalid item name', g.aux_auctionable_items
elseif type(input_type) == 'table' then
@@ -318,7 +318,7 @@ function public.parse_query_string(str)
end
function public.query(query_string)
local components, error, suggestions = m.parse_query_string(query_string)
local components, error, suggestions = parse_query_string(query_string)
if not components then
return nil, suggestions or {}, error
@@ -336,8 +336,8 @@ function public.query(query_string)
if polish_notation_counter > 0 then
local suggestions = {}
for filter, _ in m.filters do
tinsert(suggestions, strlower(filter))
for key in filters do
tinsert(suggestions, strlower(key))
end
tinsert(suggestions, 'and')
tinsert(suggestions, 'or')
@@ -346,9 +346,9 @@ function public.query(query_string)
end
return {
blizzard_query = m.blizzard_query(components),
validator = m.validator(components),
prettified = m.prettified_query_string(components),
blizzard_query = blizzard_query(components),
validator = validator(components),
prettified = prettified_query_string(components),
}, m.suggestions(components)
end
@@ -359,7 +359,7 @@ function public.queries(query_string)
for _, str in parts do
str = trim(str)
local query, _, error = m.query(str)
local query, _, error = query(str)
if not query then
log('Invalid filter:', error)
@@ -384,8 +384,8 @@ function suggestions(components)
tinsert(suggestions, 'not')
tinsert(suggestions, 'tt')
for filter, _ in m.filters do
tinsert(suggestions, filter)
for key in filters do
tinsert(suggestions, key)
end
-- classes
@@ -432,7 +432,7 @@ function suggestions(components)
end
function public.query_string(components)
local query_builder = m.query_builder()
local query_builder = query_builder()
for _, filter in components.blizzard do
query_builder.append((filter[2] or filter[1]))
@@ -456,7 +456,7 @@ function public.query_string(components)
end
function prettified_query_string(components)
local prettified = m.query_builder()
local prettified = query_builder()
for key, filter in components.blizzard do
if key == 'exact' then
@@ -481,7 +481,7 @@ function prettified_query_string(components)
if component[2] == 'item' then
prettified.append(aux.info.display_name(aux.cache.item_id(parameter)) or aux.gui.color.label.enabled('['..parameter..']'))
else
if m.filters[component[2]].input_type == 'money' then
if filters[component[2]].input_type == 'money' then
prettified.append(aux.money.to_string(aux.money.from_string(parameter), nil, true, nil, aux.gui.inline_color.label.enabled))
else
prettified.append(aux.gui.color.label.enabled(parameter))
@@ -511,7 +511,7 @@ function blizzard_query(components)
local query = {name=filters.name and filters.name[2]}
local item_info, class_index, subclass_index, slot_index
if filters.exact and temp(aux.cache.item_id(filters.name[2])) and temp(aux.info.item(__)) then
if filters.exact and x(aux.cache.item_id(filters.name[2])) and x(aux.info.item(__)) then
item_info = __
class_index = aux.info.item_class_index(item_info.class)
subclass_index = aux.info.item_subclass_index(class_index or 0, item_info.subclass)
@@ -539,7 +539,7 @@ function validator(components)
local validators = {}
for i, component in components.post do
if component[1] == 'filter' then
validators[i] = m.filters[component[2]].validator(m.parse_parameter(m.filters[component[2]].input_type, component[3]))
validators[i] = filters[component[2]].validator(parse_parameter(filters[component[2]].input_type, component[3]))
end
end
@@ -575,10 +575,10 @@ function public.query_builder()
local filter
return {
appended = function(part)
return m.query_builder(not filter and part or filter..'/'..part)
return query_builder(not filter and part or filter..'/'..part)
end,
prepended = function(part)
return m.query_builder(not filter and part or part..'/'..filter)
return query_builder(not filter and part or part..'/'..filter)
end,
append = function(part)
filter = not filter and part or filter..'/'..part
+2 -2
View File
@@ -121,8 +121,8 @@ function public.auction(index, query_type)
link = link,
itemstring = item_info.itemstring,
item_key = item_id..':'..suffix_id,
search_signature = table.concat({item_id, suffix_id, enchant_id, start_price, buyout_price, bid_price, aux_quantity, duration, query_type == 'owner' and high_bidder or (high_bidder and 1 or 0), g.aux_ignore_owner and (aux.is_player(owner) and 0 or 1) or (owner or '?')}, ':'),
sniping_signature = table.concat({item_id, suffix_id, enchant_id, start_price, buyout_price, aux_quantity, g.aux_ignore_owner and (aux.is_player(owner, true) and 0 or 1) or (owner or '?')}, ':'),
search_signature = join({item_id, suffix_id, enchant_id, start_price, buyout_price, bid_price, aux_quantity, duration, query_type == 'owner' and high_bidder or (high_bidder and 1 or 0), g.aux_ignore_owner and (aux.is_player(owner) and 0 or 1) or (owner or '?')}, ':'),
sniping_signature = join({item_id, suffix_id, enchant_id, start_price, buyout_price, aux_quantity, g.aux_ignore_owner and (aux.is_player(owner, true) and 0 or 1) or (owner or '?')}, ':'),
name = name,
texture = texture,
+3 -3
View File
@@ -58,7 +58,7 @@ end
--function public.to_string(params) -- TODO
-- local gold, silver, copper = to_gsc(params.copper or 0 + )
-- local settings = set(unpack(arg))
-- local settings = hashset(unpack(arg))
--end
function public.to_string(money, pad, trim, decimal_points, color, no_color)
@@ -90,7 +90,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
if copper > 0 or gold == 0 and silver == 0 then
tinsert(parts, format_number(copper, pad, decimal_points, color)..copper_text)
end
text = table.concat(parts, ' ')
text = join(parts, ' ')
else
if gold > 0 then
text = format_number(gold, false, nil, color)..gold_text..' '..format_number(silver, pad, nil, color)..silver_text..' '..format_number(copper, pad, decimal_points, color)..copper_text
@@ -113,7 +113,7 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
end
function public.from_string(value)
if temp(tonumber(value)) and __ >= 0 then
if xx(tonumber(value)) and __ >= 0 then
return __ * COPPER_PER_GOLD
end
+18 -70
View File
@@ -5,18 +5,18 @@ g.aux_datasets = {}
do
local realm, faction
function m.LOAD()
aux.control.thread(aux.control.when, function() faction = UnitFactionGroup('player') return faction end, function() end)
realm = GetCVar('realmName')
function LOAD()
aux.control.thread(aux.control.when, function() faction = UnitFactionGroup 'player' return faction end, function() end)
realm = GetCVar 'realmName'
end
function get_dataset_key()
function accessor.dataset_key()
return realm..'|'..faction
end
end
function public.load_dataset()
local dataset_key = m.get_dataset_key()
local dataset_key = dataset_key
g.aux_datasets[dataset_key] = g.aux_datasets[dataset_key] or {}
return g.aux_datasets[dataset_key]
end
@@ -29,11 +29,11 @@ function public.read(schema, str)
elseif schema == 'number' then
return tonumber(str)
elseif type(schema) == 'table' and schema[1] == 'list' then
return m.read_list(schema, str)
return read_list(schema, str)
elseif type(schema) == 'table' and schema[1] == 'record' then
return m.read_record(schema, str)
return read_record(schema, str)
else
error('Unknown schema.')
error 'Invalid schema.'
end
end
@@ -45,24 +45,22 @@ function public.write(schema, obj)
elseif schema == 'number' then
return obj and tostring(obj) or ''
elseif type(schema) == 'table' and schema[1] == 'list' then
return m.write_list(schema, obj)
return write_list(schema, obj)
elseif type(schema) == 'table' and schema[1] == 'record' then
return m.write_record(schema, obj)
return write_record(schema, obj)
else
error('Unknown schema.')
error 'Invalid schema.'
end
end
function public.read_list(schema, str)
if str == '' then
return {}
end
if str == '' then return {} end
local separator = schema[2]
local element_type = schema[3]
local parts = split(str, separator)
return map(parts, function(part)
return m.read(element_type, part)
return read(element_type, part)
end)
end
@@ -70,9 +68,9 @@ function public.write_list(schema, list)
local separator = schema[2]
local element_type = schema[3]
local parts = map(list, function(element)
return m.write(element_type, element)
return write(element_type, element)
end)
return table.concat(parts, separator)
return join(parts, separator)
end
function public.read_record(schema, str)
@@ -81,7 +79,7 @@ function public.read_record(schema, str)
local parts = split(str, separator)
for i=3,getn(schema) do
local key, type = next(schema[i])
record[key] = m.read(type, parts[i - 2])
record[key] = read(type, parts[i - 2])
end
return record
end
@@ -91,57 +89,7 @@ function public.write_record(schema, record)
local parts = {}
for i=3,getn(schema) do
local key, type = next(schema[i])
tinsert(parts, m.write(type, record[key]))
end
return table.concat(parts, separator)
end
function public.serialize(data, separator, compactor)
local data_string = ''
local i = 1
while i <= getn(data) do
local element, count = data[i], 1
while compactor and data[i + 1] == element do
count = count + 1
i = i + 1
end
local part = count > 1 and element..compactor..count or element
data_string = data_string..(i == 1 and '' or separator)..part
i = i + 1
end
return data_string
end
function public.deserialize(data_string, separator, compactor)
if not data_string or data_string == '' then
return {}
end
local data = {}
while true do
local start_index, _ = strfind(data_string, separator, 1, true)
local part
if start_index then
part = strsub(data_string, 1, start_index - 1)
data_string = strsub(data_string, start_index + 1)
else
part = strsub(data_string, 1)
end
if compactor and strfind(part, compactor, 1, true) then
local compactor_index, _ = strfind(part, compactor, 1, true)
for i=1, tonumber(strsub(part, compactor_index + 1)) do
tinsert(data, strsub(part, 1, compactor_index - 1))
end
else
tinsert(data, part)
end
if not start_index then
return data
end
tinsert(parts, write(type, record[key]))
end
return join(parts, separator)
end