3
0
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:
Björn Ritzl 2019-03-08 09:08:34 +01:00
parent 35dd0c3f70
commit 66bdde41ed

View File

@ -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