diff --git a/buy.xml b/buy.xml
index 6cdf815..77ae4fc 100644
--- a/buy.xml
+++ b/buy.xml
@@ -374,8 +374,7 @@
-
-
+
this:RegisterForDrag("LeftButton")
this:StartMoving()
@@ -388,7 +387,7 @@
-
+
@@ -426,7 +425,6 @@
-
this:RegisterForDrag("LeftButton")
this:StartMoving()
@@ -440,7 +438,7 @@
-
+
diff --git a/control.lua b/control.lua
index 81a3e2c..b6a3bc5 100644
--- a/control.lua
+++ b/control.lua
@@ -1,35 +1,39 @@
Aux.control = {}
local event_listeners = {}
-
local update_listeners = {}
function Aux.control.on_event()
for listener, _ in pairs(event_listeners) do
- if event == listener.event then
+ if event == listener.event and not listener.deleted then
listener.action()
end
end
end
function Aux.control.on_update()
+ event_listeners = Aux.util.set_filter(event_listeners, function(l) return not l.deleted end)
+ update_listeners = Aux.util.set_filter(update_listeners, function(l) return not l.deleted end)
+
for listener, _ in pairs(update_listeners) do
- listener.action()
+ if not listener.deleted then
+ listener.action()
+ end
end
end
-function Aux.control.event_listener(event, action) -- async!
+function Aux.control.event_listener(event, action)
local self = {}
local listener = { event=event, action=action }
- function self:set_action(self, action)
+ function self.set_action(action)
listener.action = action
end
- function self:start(self)
+ function self.start()
Aux.util.set_add(event_listeners, listener)
if not Aux.util.any(event_listeners, function(l) return l.event == event end) then
AuxControlFrame:RegisterEvent(event)
@@ -37,8 +41,8 @@ function Aux.control.event_listener(event, action) -- async!
return self
end
- function self:stop(self)
- Aux.util.set_remove(event_listeners, listener)
+ function self.stop()
+ listener.deleted = true
if not Aux.util.any(event_listeners, function(l) return l.event == event end) then
AuxControlFrame:UnregisterEvent(event)
end
@@ -53,84 +57,87 @@ function Aux.control.update_listener(action)
local listener = { action=action }
- function self:set_action(self, action)
+ function self.set_action(action)
listener.action = action
end
- function self:start(self)
+ function self.start()
Aux.util.set_add(update_listeners, listener)
return self
end
- function self:stop(self)
- Aux.util.set_remove(update_listeners, listener)
+ function self.stop()
+ listener.deleted = true
return self
end
return self
end
-
+
function Aux.control.on_next_update(callback)
local listener = Aux.control.update_listener()
- listener:set_action(function()
+ listener.set_action(function()
listener:stop()
- callback()
+ return callback()
end)
- listener:start()
+ listener.start()
+end
+
+function Aux.control.on_next_event(event, callback)
+ local listener = Aux.control.event_listener(event)
+
+ listener.set_action(function()
+ listener:stop()
+ return callback()
+ end)
+
+ listener.start()
end
function Aux.control.as_soon_as(p, callback)
local listener = Aux.control.update_listener()
- listener:set_action(function()
+ listener.set_action(function()
if p() then
- callback()
- listener:stop()
+ listener.stop()
+ return callback()
end
end)
- listener:start()
-end
-
-function Aux.control.on_next_event(event, callback)
- local ok
-
- local listener = Aux.control.event_listener(event)
-
- listener:set_action(function()
- listener:stop()
- ok = true
- end)
-
- listener:start()
-
- Aux.control.as_soon_as(function() return ok end, callback)
+ listener.start()
end
-function Aux.control.timer()
+function Aux.control.controller()
local self = {}
- local t_0
+ local state
- function self:start(self)
- t_0 = GetTime()
+ local listener = Aux.control.update_listener()
+ listener.set_action(function()
+ if state and state.p() then
+ local k = state.k
+ state = nil
+ return k()
+ end
+ end)
+ listener.start()
+
+ function self.wait(p, k)
+ state = {
+ k = k,
+ p = p,
+ }
end
- function self:after(self, t, callback)
- Aux.util.as_soon_as(function() return t_0 and GetTime() - t_0 > t end, callback)
+ function self.cleanup()
+ listener.stop()
end
return self
end
-
-function Aux.control.after_time(t, callback)
- local timer = Aux.control.timer()
- timer:start()
- timer:after(t, callback)
-end
diff --git a/control.xml b/control.xml
index 778c193..52db94d 100644
--- a/control.xml
+++ b/control.xml
@@ -2,7 +2,7 @@
-
+
Aux.control.on_event()
diff --git a/scan.lua b/scan.lua
index 02ba234..3e238a7 100644
--- a/scan.lua
+++ b/scan.lua
@@ -2,110 +2,79 @@ Aux.scan = {}
local AUCTIONS_PER_PAGE = 50
-
+local controller = (function()
+ local controller
+ return function()
+ controller = controller or Aux.control.controller()
+ return controller
+ end
+end)()
local state, abort, new_job
-- forward declaration of local functions
-local wait, wait_after, wait_for_function, wait_until, listen_for_event
+local wait_for_callback, wait_for_results, wait_for_update
local scan, scan_auctions, scan_auctions_helper, submit_query
-function Aux.scan.on_update()
- if abort then
- if state and state.job and state.job.on_abort then
- state.job.on_abort()
- end
- state = nil
- abort = false
- elseif new_job then
- state = {
- job = new_job,
- page = new_job.page
- }
- new_job = nil
- scan()
- elseif state and state.ready and state.ready() then
- state.ready = nil
- state.continuation()
- end
-end
-
function Aux.scan.start(job)
- abort = true
- new_job = job
+ Aux.scan.abort(function() --;
+ wait_for_update(function() --;
+ state = {
+ job = job,
+ page = job.page
+ }
+ return scan()
+ end)end)
end
-function Aux.scan.abort()
- abort = true
+function Aux.scan.abort(k)
+ wait_for_update(function() --;
+ if state and state.job and state.job.on_abort then
+ state.job.on_abort()
+ end
+ state = nil
+
+ if k then
+ return k()
+ end
+ end)
end
-function wait(timeout, k)
- state.continuation = k
- local start_time = GetTime()
- state.ready = function()
- return GetTime() - start_time >= timeout
- end
+function wait_for_results(k)
+ local ok
+ Aux.control.on_next_event('AUCTION_ITEM_LIST_UPDATE', function()
+ ok = true
+ end)
+
+ return controller().wait(function() return ok end, k)
end
-function wait_from()
- local from
- return function()
- from = GetTime()
- end,
- function(timeout, k)
- state.continuation = k
- state.ready = function()
- return from and GetTime() - from >= timeout
- end
- end
+function wait_for_update(k)
+ return controller().wait(function() return true end, k)
end
-function listen_for_event(e)
- local occurred
- Aux.scan.on_event = function()
- if event == e then
- occurred = true
- end
- end
- return function(k)
- state.continuation = k
- state.ready = function()
- return occurred
- end
- end
-end
-
-function wait_for_function(f, args, k)
- state.continuation = k
- local complete
- state.ready = function()
- return complete
- end
+function wait_for_callback(f, args, k)
+ local ok
if not f then
- complete = true
+ ok = true
else
- tinsert(args, 1, function() complete = true end)
+ tinsert(args, 1, function() ok = true end)
f(unpack(args))
end
-end
-function wait_until(p, k)
- state.continuation = k
- state.ready = function()
- return p()
- end
+ return controller().wait(function() return ok end, k)
end
function scan()
- wait_for_function(state.job.on_start_page, {state.page}, function() --;
+ wait_for_callback(state.job.on_start_page, {state.page}, function() --;
submit_query(function() --;
@@ -123,17 +92,18 @@ function scan()
if state.job.on_complete then
state.job.on_complete()
end
+ state = nil
end
end)end)end)
end
function scan_auctions(count, k)
- scan_auctions_helper(1, count, k)
+ return scan_auctions_helper(1, count, k)
end
function scan_auctions_helper(i, n, k)
- wait_for_function(state.job.on_read_auction, {i}, function() --;
+ wait_for_callback(state.job.on_read_auction, {i}, function() --;
if i >= n then
return k()
@@ -146,8 +116,8 @@ end
function submit_query(k)
if state.page then
- wait_until(CanSendAuctionQuery, function() --;
- local wait_for_event = listen_for_event('AUCTION_ITEM_LIST_UPDATE')
+ controller().wait(CanSendAuctionQuery, function() --;
+ wait_for_results(k)
QueryAuctionItems(
state.job.query.name,
state.job.query.min_level,
@@ -159,10 +129,8 @@ function submit_query(k)
state.job.query.usable,
state.job.query.quality
)
- wait_for_event(k)
-
end)
else
- k()
+ return k()
end
end
\ No newline at end of file
diff --git a/scan.xml b/scan.xml
index 26d99b3..17cb2d5 100644
--- a/scan.xml
+++ b/scan.xml
@@ -1,19 +1,5 @@
-
-
-
-
-
- this:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
-
-
- Aux.scan.on_event()
-
-
- Aux.scan.on_update()
-
-
-
+
\ No newline at end of file
diff --git a/sell.lua b/sell.lua
index 41a5d15..98dbaf7 100644
--- a/sell.lua
+++ b/sell.lua
@@ -506,7 +506,7 @@ end
-----------------------------------------
function report(item_name, stack_size, buyout_price, posted)
- AuxBuyReportHTML:SetText(string.format(
+ AuxSellReportHTML:SetText(string.format(
[[
@@ -528,7 +528,7 @@ function report(item_name, stack_size, buyout_price, posted)
Aux.util.format_money(buyout_price)
))
- AuxBuyReportHTML:SetSpacing(3)
+ AuxSellReportHTML:SetSpacing(3)
- AuxBuyReport:Show()
+ AuxSellReport:Show()
end
diff --git a/sell.xml b/sell.xml
index 6b40db8..ee2f315 100644
--- a/sell.xml
+++ b/sell.xml
@@ -395,7 +395,7 @@
-
+
@@ -406,8 +406,8 @@
-
-
+
+
@@ -418,7 +418,7 @@
- AuxBuyReport:Hide()
+ AuxSellReport:Hide()
diff --git a/util.lua b/util.lua
index db35f09..cc688c7 100644
--- a/util.lua
+++ b/util.lua
@@ -83,4 +83,14 @@ function Aux.util.all(xs, p)
holds = holds and p(x)
end
return holds
+end
+
+function Aux.util.set_filter(set, p)
+ filtered = {}
+ for x, _ in pairs(set) do
+ if p(x) then
+ Aux.util.set_add(filtered, x)
+ end
+ end
+ return filtered
end
\ No newline at end of file