mirror of
https://github.com/britzl/monarch.git
synced 2025-06-27 10:27:49 +02:00
Make sure to pcall when invoking callbacks
This commit is contained in:
parent
35dd0c3f70
commit
66bdde41ed
@ -61,6 +61,12 @@ local function tohash(s)
|
|||||||
return hash_lookup[s]
|
return hash_lookup[s]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function pcallfn(fn, ...)
|
||||||
|
if fn then
|
||||||
|
local ok, err = pcall(fn, ...)
|
||||||
|
if not ok then print(err) end
|
||||||
|
end
|
||||||
|
end
|
||||||
local function notify_transition_listeners(message_id, message)
|
local function notify_transition_listeners(message_id, message)
|
||||||
log("notify_transition_listeners()", message_id)
|
log("notify_transition_listeners()", message_id)
|
||||||
for _,url in pairs(transition_listeners) do
|
for _,url in pairs(transition_listeners) do
|
||||||
@ -646,8 +652,8 @@ function M.hide(id, cb)
|
|||||||
else
|
else
|
||||||
if M.is_visible(id) then
|
if M.is_visible(id) then
|
||||||
back_out(screen, nil, cb)
|
back_out(screen, nil, cb)
|
||||||
elseif cb then
|
else
|
||||||
cb()
|
pcallfn(cb)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -713,7 +719,7 @@ function M.preload(id, cb)
|
|||||||
local screen = screens[id]
|
local screen = screens[id]
|
||||||
log("preload()", screen.id)
|
log("preload()", screen.id)
|
||||||
if screen.preloaded or screen.loaded then
|
if screen.preloaded or screen.loaded then
|
||||||
if cb then cb() end
|
pcallfn(cb)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local co
|
local co
|
||||||
@ -746,7 +752,7 @@ function M.unload(id, cb)
|
|||||||
local screen = screens[id]
|
local screen = screens[id]
|
||||||
if not screen.preloaded and not screen.loaded then
|
if not screen.preloaded and not screen.loaded then
|
||||||
log("unload() screen is not loaded", tostring(id))
|
log("unload() screen is not loaded", tostring(id))
|
||||||
if cb then cb() end
|
pcallfn(cb)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
local co
|
local co
|
||||||
|
Loading…
x
Reference in New Issue
Block a user