From owner-svn-src-head@freebsd.org Mon Mar 26 19:01:23 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6F78DF60FD2; Mon, 26 Mar 2018 19:01:23 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1E7436D5E6; Mon, 26 Mar 2018 19:01:23 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1921710E39; Mon, 26 Mar 2018 19:01:23 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2QJ1MM6074383; Mon, 26 Mar 2018 19:01:22 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2QJ1MUj074381; Mon, 26 Mar 2018 19:01:22 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201803261901.w2QJ1MUj074381@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 26 Mar 2018 19:01:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331563 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 331563 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2018 19:01:23 -0000 Author: kevans Date: Mon Mar 26 19:01:22 2018 New Revision: 331563 URL: https://svnweb.freebsd.org/changeset/base/331563 Log: 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 Modified: head/stand/lua/core.lua head/stand/lua/loader.lua Modified: head/stand/lua/core.lua ============================================================================== --- head/stand/lua/core.lua Mon Mar 26 18:39:38 2018 (r331562) +++ head/stand/lua/core.lua Mon Mar 26 19:01:22 2018 (r331563) @@ -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 Modified: head/stand/lua/loader.lua ============================================================================== --- head/stand/lua/loader.lua Mon Mar 26 18:39:38 2018 (r331562) +++ head/stand/lua/loader.lua Mon Mar 26 19:01:22 2018 (r331563) @@ -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