Changeset View
Changeset View
Standalone View
Standalone View
stand/lua/core.lua
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | if boot_acpi then | ||||
core.setACPI(true) | core.setACPI(true) | ||||
end | end | ||||
core.setSingleUser(default_single_user) | core.setSingleUser(default_single_user) | ||||
core.setVerbose(default_verbose) | core.setVerbose(default_verbose) | ||||
end | end | ||||
-- Globals | -- Globals | ||||
-- try_include will return the loaded module on success, or false and the error | -- try_include will return the loaded module or true on success (module loaded | ||||
-- message on failure. | -- or file does not exist), or false and the error message on failure. | ||||
function try_include(module) | function try_include(module) | ||||
if module:sub(1, 1) ~= "/" then | if module:sub(1, 1) ~= "/" then | ||||
local lua_path = loader.lua_path | local lua_path = loader.lua_path | ||||
-- XXX Temporary compat shim; this should be removed once the | -- XXX Temporary compat shim; this should be removed once the | ||||
-- loader.lua_path export has sufficiently spread. | -- loader.lua_path export has sufficiently spread. | ||||
if lua_path == nil then | if lua_path == nil then | ||||
lua_path = "/boot/lua" | lua_path = "/boot/lua" | ||||
end | end | ||||
module = lua_path .. "/" .. module | module = lua_path .. "/" .. module | ||||
-- We only attempt to append an extension if an absolute path | -- We only attempt to append an extension if an absolute path | ||||
-- wasn't specified. This assumes that the caller either wants | -- wasn't specified. This assumes that the caller either wants | ||||
-- to treat this like it would require() and specify just the | -- to treat this like it would require() and specify just the | ||||
-- base filename, or they know what they're doing as they've | -- base filename, or they know what they're doing as they've | ||||
-- specified an absolute path and we shouldn't impede. | -- specified an absolute path and we shouldn't impede. | ||||
if module:match(".lua$") == nil then | if module:match(".lua$") == nil then | ||||
module = module .. ".lua" | module = module .. ".lua" | ||||
end | end | ||||
end | end | ||||
if lfs.attributes(module, "mode") ~= "file" then | |||||
return | -- If the file doesn't exist, just pretend we succeeded... if it does | ||||
-- exist but it's not a regular file, then that's an actual error. | |||||
-- try_include doesn't guarantee that it won't trip over weird entries, | |||||
-- just that it won't trip over nonexistent entries. | |||||
local mode = lfs.attributes(module, 'mode') | |||||
if not mode then | |||||
return true | |||||
elseif mode ~= "file" then | |||||
return nil, module .. " is not a regular file." | |||||
end | end | ||||
return dofile(module) | local function unwrap_result(res, mod, ...) | ||||
if res then | |||||
return mod or true, ... | |||||
else | |||||
return res, mod | |||||
end | |||||
end | |||||
return unwrap_result(pcall(dofile, module)) | |||||
end | end | ||||
-- Module exports | -- Module exports | ||||
-- Commonly appearing constants | -- Commonly appearing constants | ||||
core.KEY_BACKSPACE = 8 | core.KEY_BACKSPACE = 8 | ||||
core.KEY_ENTER = 13 | core.KEY_ENTER = 13 | ||||
core.KEY_DELETE = 127 | core.KEY_DELETE = 127 | ||||
▲ Show 20 Lines • Show All 404 Lines • Show Last 20 Lines |