refactoring
This commit is contained in:
+3
-3
@@ -58,7 +58,7 @@ end
|
||||
|
||||
function public.event_listener(event, cb)
|
||||
local listener_id = unique_id
|
||||
listeners[listener_id] = {event=event, cb=cb, kill=function(...) auto[arg] = true if arg.n == 0 or arg[1] then kill_listener(listener_id) end end}
|
||||
listeners[listener_id] = { event=event, cb=cb, kill=function(...) auto[arg] = true if arg.n == 0 or arg[1] then kill_listener(listener_id) end end }
|
||||
event_frame:RegisterEvent(event)
|
||||
return listener_id
|
||||
end
|
||||
@@ -69,7 +69,7 @@ end
|
||||
|
||||
function public.thread(k, ...) auto[arg] = true
|
||||
local thread_id = unique_id
|
||||
threads[thread_id] = T('k', L(k, unpack(arg)))
|
||||
threads[thread_id] = T('k', partial(k, unpack(arg)))
|
||||
return thread_id
|
||||
end
|
||||
|
||||
@@ -77,7 +77,7 @@ function public.wait(k, ...) auto[arg] = true
|
||||
if type(k) == 'number' then
|
||||
when(function() k = k - 1 return k <= 1 end, unpack(arg))
|
||||
else
|
||||
threads[thread_id].k = L(k, unpack(arg))
|
||||
threads[thread_id].k = partial(k, unpack(arg))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ function scan_page(i)
|
||||
if (state.params.auto_buy_validator or nop)(auction_info) then
|
||||
local send_signal, signal_received = signal()
|
||||
when(signal_received, recurse)
|
||||
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, L(send_signal, true))
|
||||
place_bid(auction_info.query_type, auction_info.index, auction_info.buyout_price, partial(send_signal, true))
|
||||
return thread(when, later(GetTime(), 10), 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)
|
||||
|
||||
@@ -35,7 +35,7 @@ do
|
||||
btn:SetPoint('BOTTOMRIGHT', -5, 5)
|
||||
gui.set_size(btn, 60, 24)
|
||||
btn:SetText('Close')
|
||||
btn:SetScript('OnClick', L(aux_frame.Hide, aux_frame))
|
||||
btn:SetScript('OnClick', partial(aux_frame.Hide, aux_frame))
|
||||
public.close_button = btn
|
||||
end
|
||||
do
|
||||
|
||||
@@ -78,7 +78,7 @@ do
|
||||
|
||||
cancel_button:SetScript('OnClick', function()
|
||||
if test(record)(index) and listing:ContainsRecord(record) then
|
||||
cancel_auction(index, L(listing.RemoveAuctionRecord, listing, record))
|
||||
cancel_auction(index, partial(listing.RemoveAuctionRecord, listing, record))
|
||||
end
|
||||
end)
|
||||
cancel_button:Enable()
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ do
|
||||
place_bid('bidder', index, record.bid_price, record.bid_price < record.buyout_price and function()
|
||||
aux.info.bid_update(record)
|
||||
listing:SetDatabase()
|
||||
end or L(listing.RemoveAuctionRecord, listing, record))
|
||||
end or partial(listing.RemoveAuctionRecord, listing, record))
|
||||
end
|
||||
end)
|
||||
bid_button:Enable()
|
||||
@@ -94,7 +94,7 @@ do
|
||||
if record.buyout_price > 0 then
|
||||
buyout_button:SetScript('OnClick', function()
|
||||
if test(record)(index) and listing:ContainsRecord(record) then
|
||||
place_bid('bidder', index, record.buyout_price, L(listing.RemoveAuctionRecord, listing, record))
|
||||
place_bid('bidder', index, record.buyout_price, partial(listing.RemoveAuctionRecord, listing, record))
|
||||
end
|
||||
end)
|
||||
buyout_button:Enable()
|
||||
|
||||
@@ -353,7 +353,7 @@ function create_frames()
|
||||
end
|
||||
end)
|
||||
editbox.change = update_form
|
||||
editbox.enter = L(editbox.ClearFocus, editbox)
|
||||
editbox.enter = partial(editbox.ClearFocus, editbox)
|
||||
local label = gui.label(editbox, gui.font_size.small)
|
||||
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
|
||||
label:SetText('Name')
|
||||
@@ -380,7 +380,7 @@ function create_frames()
|
||||
max_level_input:SetFocus()
|
||||
end
|
||||
end)
|
||||
editbox.enter = L(editbox.ClearFocus, editbox)
|
||||
editbox.enter = partial(editbox.ClearFocus, editbox)
|
||||
editbox.change = function()
|
||||
local valid_level = valid_level(this:GetText())
|
||||
if tostring(valid_level) ~= this:GetText() then
|
||||
@@ -405,7 +405,7 @@ function create_frames()
|
||||
name_input:SetFocus()
|
||||
end
|
||||
end)
|
||||
editbox.enter = L(editbox.ClearFocus, editbox)
|
||||
editbox.enter = partial(editbox.ClearFocus, editbox)
|
||||
editbox.change = function()
|
||||
local valid_level = valid_level(this:GetText())
|
||||
if tostring(valid_level) ~= this:GetText() then
|
||||
|
||||
@@ -165,7 +165,7 @@ function start_real_time_scan(query, search, continuation)
|
||||
if not ignore_page then
|
||||
if search.auto_buy then
|
||||
ctrl.suspend()
|
||||
place_bid('list', auction_record.index, auction_record.buyout_price, L(ctrl.resume, true))
|
||||
place_bid('list', auction_record.index, auction_record.buyout_price, partial(ctrl.resume, true))
|
||||
thread(when, later(GetTime(), 10), ctrl.resume, false)
|
||||
else
|
||||
tinsert(new_records, auction_record)
|
||||
@@ -258,7 +258,7 @@ function start_search(queries, continuation)
|
||||
on_auction = function(auction_record, ctrl)
|
||||
if search.auto_buy then
|
||||
ctrl.suspend()
|
||||
place_bid('list', auction_record.index, auction_record.buyout_price, L(ctrl.resume, true))
|
||||
place_bid('list', auction_record.index, auction_record.buyout_price, partial(ctrl.resume, true))
|
||||
thread(when, later(GetTime(), 10), ctrl.resume, false)
|
||||
elseif getn(search.records) < 1000 then
|
||||
tinsert(search.records, auction_record)
|
||||
@@ -411,7 +411,7 @@ do
|
||||
place_bid('list', index, record.bid_price, record.bid_price < record.buyout_price and function()
|
||||
info.bid_update(record)
|
||||
search.table:SetDatabase()
|
||||
end or L(search.table.RemoveAuctionRecord, search.table, record))
|
||||
end or partial(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
|
||||
place_bid('list', index, record.buyout_price, L(search.table.RemoveAuctionRecord, search.table, record))
|
||||
place_bid('list', index, record.buyout_price, partial(search.table.RemoveAuctionRecord, search.table, record))
|
||||
end
|
||||
end)
|
||||
buyout_button:Enable()
|
||||
|
||||
+14
-14
@@ -44,6 +44,18 @@ aux 'core'
|
||||
-- end
|
||||
--end
|
||||
|
||||
do
|
||||
local _state = setmetatable(t, T('__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) -- TODO rename table-accessor, use predicate to stop
|
||||
local state, self = {handler=handler, state=state}, t
|
||||
_state[self] = state
|
||||
return setmetatable(self, { __metatable=false, __index=__index, state=state })
|
||||
end
|
||||
end
|
||||
|
||||
function public.vararg.select(arg)
|
||||
for _ = 1, arg[1] do
|
||||
tremove(arg, 1)
|
||||
@@ -79,9 +91,9 @@ do
|
||||
end
|
||||
end
|
||||
|
||||
function public.vararg.L(arg)
|
||||
function public.vararg.partial(arg)
|
||||
local f = tremove(arg, 1)
|
||||
local arg1 = perm-arg
|
||||
local arg1 = copy(arg)
|
||||
return vararg(function(arg)
|
||||
for i = 1, getn(arg) do
|
||||
tinsert(arg1, arg[i])
|
||||
@@ -98,18 +110,6 @@ public.huge = 1.8 * 10 ^ 308
|
||||
|
||||
function public.modified.get() return IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() end
|
||||
|
||||
do
|
||||
local _state = setmetatable(t, T('__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) -- TODO rename table-accessor, use predicate to stop
|
||||
local state, self = {handler=handler, state=state}, t
|
||||
_state[self] = state
|
||||
return setmetatable(self, {__metatable=false, __index=__index, state=state})
|
||||
end
|
||||
end
|
||||
|
||||
function public.copy(t)
|
||||
local copy = _E.t
|
||||
for k, v in t do copy[k] = v end
|
||||
|
||||
+2
-2
@@ -233,8 +233,8 @@ do
|
||||
end
|
||||
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)),
|
||||
temp-A('slot', L(info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0)),
|
||||
temp-A('subclass', partial(info.item_subclass_index, index(self.class, 2) or 0)),
|
||||
temp-A('slot', partial(info.item_slot_index, index(self.class, 2) or 0, index(self.subclass, 2) or 0)),
|
||||
temp-A('quality', info.item_quality_index)
|
||||
) do
|
||||
if not self[parser[1]] then
|
||||
|
||||
Reference in New Issue
Block a user