ppm function renames, edited log messages, and changed protected calls to return true if function has no return

This commit is contained in:
Mikayla Fischler
2022-03-10 14:21:03 -05:00
parent a0b2c1f3e2
commit 5cff346cb5

View File

@@ -16,10 +16,15 @@ local peri_init = function (device)
local status, result = pcall(func, ...) local status, result = pcall(func, ...)
if status then if status then
return result -- assume nil is only for functions with no return, so return status
if result == nil then
return true
else
return result
end
else else
-- function failed -- function failed
log._error("protected " .. key .. "() -> " .. result) log._error("PPM: protected " .. key .. "() -> " .. result)
return nil return nil
end end
end end
@@ -37,6 +42,10 @@ function mount_all()
peri_init(pm_dev) peri_init(pm_dev)
self.mounts[ifaces[i]] = { peripheral.getType(ifaces[i]), pm_dev } self.mounts[ifaces[i]] = { peripheral.getType(ifaces[i]), pm_dev }
end end
if #ifaces == 0 then
log._warning("PPM: mount_all() -> no devices found")
end
end end
-- mount a particular device -- mount a particular device
@@ -61,12 +70,12 @@ function mount(name)
end end
-- handle peripheral_detach event -- handle peripheral_detach event
function unmount_handler(iface) function handle_unmount(iface)
-- what got disconnected? -- what got disconnected?
local lost_dev = self.mounts[iface] local lost_dev = self.mounts[iface]
local type = lost_dev.type local type = lost_dev.type
log._warning("PMGR: lost device " .. type .. " mounted to " .. iface) log._warning("PPM: lost device " .. type .. " mounted to " .. iface)
return self.mounts[iface] return self.mounts[iface]
end end