Index: stand/liblua/lutils.c =================================================================== --- stand/liblua/lutils.c +++ stand/liblua/lutils.c @@ -338,6 +338,36 @@ return 1; } +/* + * Implements try_include(modname) + * Attempts to require(modname), but silently fails instead of raising an + * error. Returns nil if it failed to load, or the value that would have been + * returned by require if it succeeded. + */ +static int +lua_try_include(lua_State *L) +{ + const char *mod_name; + int status; + + if (lua_gettop(L) != 1 || !lua_isstring(L, 1)) { + lua_pushnil(L); + return 1; + } + + mod_name = lua_tostring(L, 1); + lua_getglobal(L, "require"); + lua_pushstring(L, mod_name); + status = lua_pcall(L, 1, 1, 0); + /* Push the return of require(modname) as return value */ + if (status == LUA_OK) + return 1; + /* Otherwise, just silently push nil and return */ + lua_pop(L, 1); + lua_pushnil(L); + return 1; +} + #define REG_SIMPLE(n) { #n, lua_ ## n } static const struct luaL_Reg loaderlib[] = { REG_SIMPLE(delay), @@ -377,6 +407,7 @@ lua_setfield(L, -2, "machine_arch"); /* Set global printc to loader.printc */ lua_register(L, "printc", lua_printc); + lua_register(L, "try_include", lua_try_include); return 1; } Index: stand/lua/loader.lua =================================================================== --- stand/lua/loader.lua +++ stand/lua/loader.lua @@ -41,12 +41,7 @@ menu = require("menu") 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() password.check()