diff --git a/auctions_frame.xml b/auctions_frame.xml
index 6b9072a..e4606f3 100644
--- a/auctions_frame.xml
+++ b/auctions_frame.xml
@@ -2,15 +2,12 @@
-
+
Aux.auctions_frame.on_update()
-
-
-
diff --git a/bids_frame.xml b/bids_frame.xml
index 5f9eff2..3578551 100644
--- a/bids_frame.xml
+++ b/bids_frame.xml
@@ -2,15 +2,12 @@
-
+
Aux.bids_frame.on_update()
-
-
-
diff --git a/control.lua b/control.lua
index f59fe3f..1f50964 100644
--- a/control.lua
+++ b/control.lua
@@ -1,27 +1,19 @@
local private, public = {}, {}
Aux.control = public
-local event_listeners = {}
-local update_listeners = {}
+private.event_listeners = {}
private.threads = {}
-function Aux.control.on_event()
- for listener, _ in pairs(event_listeners) do
+function public.on_event()
+ for listener, _ in pairs(private.event_listeners) do
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
- if not listener.deleted then
- listener.action()
- end
- end
+function public.on_update()
+ private.event_listeners = Aux.util.set_filter(private.event_listeners, function(l) return not l.deleted end)
for thread_id, k in pairs(private.threads) do
private.threads[thread_id] = nil
@@ -31,9 +23,7 @@ function Aux.control.on_update()
end
end
-
-
-function Aux.control.event_listener(event, action)
+function public.event_listener(event, action)
local self = {}
local listener = { event=event, action=action }
@@ -43,14 +33,14 @@ function Aux.control.event_listener(event, action)
end
function self:start()
- Aux.util.set_add(event_listeners, listener)
+ Aux.util.set_add(private.event_listeners, listener)
AuxControlFrame:RegisterEvent(event)
return self
end
function self:stop()
listener.deleted = true
- if not Aux.util.any(Aux.util.set_to_array(event_listeners), function(l) return l.event == event end) then
+ if not Aux.util.any(Aux.util.set_to_array(private.event_listeners), function(l) return l.event == event end) then
AuxControlFrame:UnregisterEvent(event)
end
return self
@@ -59,32 +49,8 @@ function Aux.control.event_listener(event, action)
return self
end
-function Aux.control.update_listener(action)
- local self = {}
-
- local listener = { action=action }
-
- function self:set_action(action)
- listener.action = action
- end
-
- function self:start()
- Aux.util.set_add(update_listeners, listener)
- return self
- end
-
- 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()
+function public.on_next_event(event, callback)
+ local listener = public.event_listener(event)
listener:set_action(function()
listener:stop()
@@ -94,68 +60,19 @@ function Aux.control.on_next_update(callback)
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()
+function public.on_next_update(callback)
+ return public.new_thread(callback)
end
-function Aux.control.as_soon_as(p, callback)
- local listener = Aux.control.update_listener()
-
- listener:set_action(function()
- if p() then
- listener:stop()
- return callback()
- end
+function public.as_soon_as(p, callback)
+ return public.new_thread(function()
+ return public.wait_until(p, callback)
end)
-
- listener:start()
-end
-
-
-
-function Aux.control.controller()
- local self = {}
-
- local state
-
- 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:reset()
- state = nil
- end
-
- function self:cleanup()
- listener.stop()
- end
-
- return self
end
do
local next_thread_id = 1
- function public.new(k)
+ function public.new_thread(k)
local thread_id = next_thread_id
next_thread_id = next_thread_id + 1
private.threads[thread_id] = k
@@ -163,7 +80,7 @@ do
end
end
-function public.kill(thread_id)
+function public.kill_thread(thread_id)
private.threads[thread_id] = nil
end
@@ -171,3 +88,12 @@ function public.wait(...)
local k = tremove(arg, 1)
private.threads[public.thread_id] = function() return k(unpack(arg)) end
end
+
+function public.wait_until(p, ...)
+ local k = tremove(arg, 1)
+ if p() then
+ return k(unpack(arg))
+ else
+ return public.wait(public.wait_until, p, function() return k(unpack(arg)) end)
+ end
+end
diff --git a/core.xml b/core.xml
index c061ea3..9c7fa59 100644
--- a/core.xml
+++ b/core.xml
@@ -1,7 +1,7 @@
-
-
+
+
@@ -12,9 +12,9 @@
this:RegisterEvent('AUCTION_BIDDER_LIST_UPDATE')
this:RegisterEvent('AUCTION_OWNED_LIST_UPDATE')
-
+
Aux.on_event()
-
+
diff --git a/post.lua b/post.lua
index eb43141..e3c2dbc 100644
--- a/post.lua
+++ b/post.lua
@@ -3,14 +3,6 @@ Aux.post = public
local state
-function private.as_soon_as(p, k)
- if p() then
- return k()
- else
- return Aux.control.wait(private.as_soon_as, p, k)
- end
-end
-
function private.process()
if state.posted < state.count or state.allow_partial then
if state.posted == state.count then
@@ -29,7 +21,7 @@ function private.process()
end
)
- private.as_soon_as(function() return stacking_complete end, function()
+ Aux.control.wait_until(function() return stacking_complete end, function()
if stack_slot and Aux.info.container_item(stack_slot.bag, stack_slot.bag_slot).aux_quantity <= state.stack_size then
private.post_auction(stack_slot, function(stack_size)
@@ -58,14 +50,14 @@ function private.post_auction(slot, k)
ClearCursor()
local stack_size = Aux.info.container_item(slot.bag, slot.bag_slot).aux_quantity
StartAuction(max(1, Aux.round(state.unit_start_price * stack_size)), Aux.round(state.unit_buyout_price * stack_size), state.duration)
- private.as_soon_as(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
+ Aux.control.wait_until(function() return not GetContainerItemInfo(slot.bag, slot.bag_slot) end, function()
return k(stack_size)
end)
end
function public.stop()
if state then
- Aux.control.kill(state.thread_id)
+ Aux.control.kill_thread(state.thread_id)
local callback = state.callback
local posted = state.posted
@@ -82,7 +74,7 @@ end
function public.start(item_key, stack_size, duration, unit_start_price, unit_buyout_price, count, allow_partial, callback)
public.stop()
- local thread_id = Aux.control.new(private.process)
+ local thread_id = Aux.control.new_thread(private.process)
state = {
thread_id = thread_id,
diff --git a/post_frame.xml b/post_frame.xml
index 2ae047b..8dcff00 100644
--- a/post_frame.xml
+++ b/post_frame.xml
@@ -2,19 +2,16 @@
-
-
-
- Aux.post_frame.on_update()
-
-
-
-
+
+
+ Aux.post_frame.on_update()
+
+
diff --git a/scan.lua b/scan.lua
index 2c5c4c8..a5c7ab8 100644
--- a/scan.lua
+++ b/scan.lua
@@ -30,7 +30,7 @@ end
function public.start(params)
public.abort(params.type)
- local thread_id = Aux.control.new(private.scan)
+ local thread_id = Aux.control.new_thread(private.scan)
threads[params.type] = {
id = thread_id,
params = params,
@@ -44,19 +44,11 @@ function public.abort(type)
thread.params.on_abort()
end
threads[t] = nil
- Aux.control.kill(thread.id)
+ Aux.control.kill_thread(thread.id)
end
end
end
-function private.as_soon_as(p, k)
- if p() then
- return k()
- else
- return Aux.control.wait(private.as_soon_as, p, k)
- end
-end
-
function private.wait_for_results(k)
if current_thread().params.type == 'bidder' then
return private.wait_for_bidder_results(k)
@@ -85,7 +77,7 @@ function private.wait_for_owner_results(k)
end)
end
- private.as_soon_as(function() return updated end, k)
+ Aux.control.wait_until(function() return updated end, k)
end
function private.wait_for_list_results(k)
@@ -95,7 +87,7 @@ function private.wait_for_list_results(k)
updated = true
end)
listener:start()
- private.as_soon_as(function()
+ Aux.control.wait_until(function()
-- order important, owner_data_complete must be called after an update to request missing data
local ok = updated and private.owner_data_complete() or last_update and GetTime() - last_update > 5
updated = false
@@ -137,7 +129,7 @@ function wait_for_callback(args) -- the arguments must not be nil!
if ok then
return k()
else
- return private.as_soon_as(function() return ok end, k)
+ return Aux.control.wait_until(function() return ok end, k)
end
end
@@ -218,7 +210,7 @@ end
function submit_query(k)
if current_thread().page then
- private.as_soon_as(function() return current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
+ Aux.control.wait_until(function() return current_thread().params.type ~= 'list' or CanSendAuctionQuery() end, function()
if current_thread().params.on_submit_query then
current_thread().params.on_submit_query()
diff --git a/search_frame.xml b/search_frame.xml
index da0ddf9..95a8123 100644
--- a/search_frame.xml
+++ b/search_frame.xml
@@ -2,15 +2,12 @@
-
+
Aux.search_frame.on_update()
-
-
-
diff --git a/stack.lua b/stack.lua
index 952aef7..0d9fd7d 100644
--- a/stack.lua
+++ b/stack.lua
@@ -1,14 +1,6 @@
local private, public = {}, {}
Aux.stack = public
-function private.as_soon_as(p, k)
- if p() then
- return k()
- else
- return Aux.control.wait(private.as_soon_as, p, k)
- end
-end
-
local state
function private.item_slots(item_key)
@@ -47,7 +39,7 @@ function private.move_item(from_slot, to_slot, amount, k)
SplitContainerItem(from_slot.bag, from_slot.bag_slot, amount)
PickupContainerItem(to_slot.bag, to_slot.bag_slot)
- return private.as_soon_as(function() return private.stack_size(to_slot) == size_before + amount end, k)
+ return Aux.control.wait_until(function() return private.stack_size(to_slot) == size_before + amount end, k)
end
function private.item_key(slot)
@@ -114,7 +106,7 @@ end
function public.stop()
if state then
- Aux.control.kill(state.thread_id)
+ Aux.control.kill_thread(state.thread_id)
local callback, slot = state.callback, state.target_slot
@@ -127,13 +119,13 @@ function public.stop()
end
function public.start(item_key, size, callback)
- private.as_soon_as(function()
+ Aux.control.wait_until(function()
public.stop()
local slots = private.item_slots(item_key)
local target_slot = slots()
- local thread_id = Aux.control.new(private.process)
+ local thread_id = Aux.control.new_thread(private.process)
state = {
thread_id = thread_id,