lualoader: Implement try_include and use it for including the local module

This provides a way to optionally include a module without having to wrap it
in filesystem checks. try_include is a little more robust, using the lua
search path instead of forcing us to explicitly consider all of the places
we could want to include a module. Errors are still generally raised from
trying to load the module, but ENOENT will not get raised unless we're doing
a verbose load.

This will also be used to split out logo/brand graphics into their own files
so that we can safely scale up the number of graphics included without
worrying about the extra memory consumption- opting to lazily load graphics
instead.

Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D14658
This commit is contained in:
Kyle Evans 2018-03-26 19:01:22 +00:00
parent 60fde7ce5d
commit 07faaf7815
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=331563
2 changed files with 21 additions and 5 deletions

View File

@ -41,6 +41,26 @@ local function composeLoaderCmd(cmd_name, argstr)
return cmd_name
end
-- Globals
-- try_include will return the loaded module on success, or nil on failure.
-- A message will also be printed on failure, with one exception: non-verbose
-- loading will suppress 'module not found' errors.
function try_include(module)
local status, ret = pcall(require, module)
-- ret is the module if we succeeded.
if status then
return ret
end
-- Otherwise, ret is just a message; filter out ENOENT unless we're
-- doing a verbose load. As a consequence, try_include prior to loading
-- configuration will not display 'module not found'. All other errors
-- in loading will be printed.
if config.verbose or ret:match("^module .+ not found") == nil then
print(ret)
end
return nil
end
-- Module exports
-- Commonly appearing constants
core.KEY_BACKSPACE = 8

View File

@ -43,11 +43,7 @@ if not core.isMenuSkipped() then
end
local password = require("password")
local result = lfs.attributes("/boot/lua/local.lua")
-- Effectively discard any errors; we'll just act if it succeeds.
if result ~= nil then
require("local")
end
try_include("local")
config.load()
if core.isUEFIBoot() then