3
0
mirror of https://github.com/britzl/monarch.git synced 2025-11-26 19:00:53 +01:00

Compare commits

..

3 Commits

Author SHA1 Message Date
Björn Ritzl
e4ca53630e Assert on coroutine.resume to catch more errors 2019-05-02 09:36:52 +02:00
Björn Ritzl
9afd77e2b0 Changed scope of top in show() 2019-05-02 09:36:23 +02:00
Björn Ritzl
9808c09aa1 Wait when reloading 2019-05-02 09:36:03 +02:00

View File

@@ -72,7 +72,7 @@ local function cowait(delay)
local co = coroutine.running() local co = coroutine.running()
assert(co, "You must run this form within a coroutine") assert(co, "You must run this form within a coroutine")
timer.delay(delay, false, function() timer.delay(delay, false, function()
coroutine.resume(co) assert(coroutine.resume(co))
end) end)
coroutine.yield() coroutine.yield()
end end
@@ -466,6 +466,11 @@ local function show_in(screen, previous_screen, reload, add_to_stack, cb)
if reload and screen.loaded then if reload and screen.loaded then
log("show_in() reloading", screen.id) log("show_in() reloading", screen.id)
unload(screen, reload) unload(screen, reload)
-- we need to wait here in case the unloaded screen contained any screens
-- if this is the case we need to let these sub-screens have their final()
-- functions called so that they have time to call unregister()
cowait(0)
cowait(0)
end end
load(screen) load(screen)
if add_to_stack then if add_to_stack then
@@ -573,13 +578,13 @@ function M.show(id, options, data, cb)
local co local co
co = coroutine.create(function() co = coroutine.create(function()
local top = stack[#stack]
-- a screen can ignore the stack by setting the no_stack to true -- a screen can ignore the stack by setting the no_stack to true
local add_to_stack = not options or not options.no_stack local add_to_stack = not options or not options.no_stack
if add_to_stack then if add_to_stack then
-- manipulate the current top -- manipulate the current top
-- close popup(s) if needed -- close popup(s) if needed
-- transition out -- transition out
local top = stack[#stack]
if top then if top then
-- keep top popup visible if new screen can be shown on top of a popup -- keep top popup visible if new screen can be shown on top of a popup
if top.popup and screen.popup_on_popup then if top.popup and screen.popup_on_popup then
@@ -589,7 +594,7 @@ function M.show(id, options, data, cb)
while top.popup do while top.popup do
stack[#stack] = nil stack[#stack] = nil
show_out(top, screen, function() show_out(top, screen, function()
coroutine.resume(co) assert(coroutine.resume(co))
end) end)
coroutine.yield() coroutine.yield()
top = stack[#stack] top = stack[#stack]
@@ -619,7 +624,7 @@ function M.show(id, options, data, cb)
-- screen that has Preload set to true -- screen that has Preload set to true
if M.is_preloading(id) then if M.is_preloading(id) then
M.when_preloaded(id, function() M.when_preloaded(id, function()
coroutine.resume(co) assert(coroutine.resume(co))
end) end)
coroutine.yield() coroutine.yield()
end end
@@ -627,7 +632,7 @@ function M.show(id, options, data, cb)
if cb then callbacks.when_done(cb) end if cb then callbacks.when_done(cb) end
end) end)
coroutine.resume(co) assert(coroutine.resume(co))
return true return true
end end