working on big scan/control refactoring
This commit is contained in:
+29
-1
@@ -1,7 +1,9 @@
|
||||
Aux.control = {}
|
||||
local private, public = {}, {}
|
||||
Aux.control = public
|
||||
|
||||
local event_listeners = {}
|
||||
local update_listeners = {}
|
||||
private.threads = {}
|
||||
|
||||
function Aux.control.on_event()
|
||||
for listener, _ in pairs(event_listeners) do
|
||||
@@ -20,6 +22,13 @@ function Aux.control.on_update()
|
||||
listener.action()
|
||||
end
|
||||
end
|
||||
|
||||
for thread_id, k in pairs(private.threads) do
|
||||
private.threads[thread_id] = nil
|
||||
public.thread_id = thread_id
|
||||
k()
|
||||
public.thread_id = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -143,3 +152,22 @@ function Aux.control.controller()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
do
|
||||
local next_thread_id = 1
|
||||
function public.new(k)
|
||||
local thread_id = next_thread_id
|
||||
next_thread_id = next_thread_id + 1
|
||||
private.threads[thread_id] = k
|
||||
return thread_id
|
||||
end
|
||||
end
|
||||
|
||||
function public.kill(thread_id)
|
||||
private.threads[thread_id] = nil
|
||||
end
|
||||
|
||||
function public.wait(...)
|
||||
local k = tremove(arg, 1)
|
||||
private.threads[public.thread_id] = function() return k(unpack(arg)) end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user