mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
lualoader: Address some 'luacheck' concerns
luacheck pointed out an assortment of issues, ranging from non-standard globals being created as well as unused parameters, variables, and redundant assignments. Using '_' as a placeholder for values unused (whether it be parameters unused or return values unused, assuming multiple return values) feels clean and gets the point across, so I've adopted it. It also helps flag candidates for cleanup later in some of the lambdas I've created, giving me an easy way to re-evaluate later if we're still not using some of these features.
This commit is contained in:
parent
03d54eb339
commit
e2df27e363
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329809
|
@ -50,7 +50,7 @@ local parse_boot_args = function(argv, with_kernel)
|
|||
local kernel_name
|
||||
local argstr = ""
|
||||
|
||||
for k, v in ipairs(argv) do
|
||||
for _, v in ipairs(argv) do
|
||||
if with_kernel and v:sub(1,1) ~= "-" then
|
||||
kernel_name = v
|
||||
else
|
||||
|
@ -92,7 +92,7 @@ end
|
|||
-- Module exports
|
||||
|
||||
function cli.boot(...)
|
||||
local cmd_name, argv = cli.arguments(...)
|
||||
local _, argv = cli.arguments(...)
|
||||
local kernel, argstr = parse_boot_args(argv)
|
||||
if kernel ~= nil then
|
||||
loader.perform("unload")
|
||||
|
@ -102,7 +102,7 @@ function cli.boot(...)
|
|||
end
|
||||
|
||||
function cli.autoboot(...)
|
||||
local cmd_name, argv = cli.arguments(...)
|
||||
local _, argv = cli.arguments(...)
|
||||
local argstr = parse_boot_args(argv, false)
|
||||
core.autoboot(argstr)
|
||||
end
|
||||
|
@ -110,7 +110,7 @@ end
|
|||
-- Used for splitting cli varargs into cmd_name and the rest of argv
|
||||
function cli.arguments(...)
|
||||
local argv = {...}
|
||||
local cmd_name = ""
|
||||
local cmd_name
|
||||
cmd_name, argv = core.popFrontTable(argv)
|
||||
return cmd_name, argv
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ local carousel_choices = {}
|
|||
pattern_table = {
|
||||
[1] = {
|
||||
str = "^%s*(#.*)",
|
||||
process = function(k, v) end
|
||||
process = function(_, _) end
|
||||
},
|
||||
-- module_load="value"
|
||||
[2] = {
|
||||
|
@ -94,7 +94,7 @@ pattern_table = {
|
|||
-- exec="command"
|
||||
[9] = {
|
||||
str = "^%s*exec%s*=%s*\"([%w%s%p]-)\"%s*(.*)",
|
||||
process = function(k, v)
|
||||
process = function(k, _)
|
||||
if loader.perform(k) ~= 0 then
|
||||
print("Failed to exec '" .. k .. "'")
|
||||
end
|
||||
|
@ -283,10 +283,7 @@ function config.parse(name, silent)
|
|||
return silent
|
||||
end
|
||||
|
||||
local text
|
||||
local r
|
||||
|
||||
text, r = io.read(f)
|
||||
local text, _ = io.read(f)
|
||||
|
||||
if text == nil then
|
||||
if not silent then
|
||||
|
@ -302,7 +299,7 @@ function config.parse(name, silent)
|
|||
if line:match("^%s*$") == nil then
|
||||
local found = false
|
||||
|
||||
for i, val in ipairs(pattern_table) do
|
||||
for _, val in ipairs(pattern_table) do
|
||||
local k, v, c = line:match(val.str)
|
||||
if k ~= nil then
|
||||
found = true
|
||||
|
@ -339,7 +336,7 @@ function config.loadkernel(other_kernel)
|
|||
|
||||
local try_load = function (names)
|
||||
for name in names:gmatch("([^;]+)%s*;?") do
|
||||
r = loader.perform("load " .. flags .. " " .. name)
|
||||
local r = loader.perform("load " .. flags .. " " .. name)
|
||||
if r == 0 then
|
||||
return name
|
||||
end
|
||||
|
@ -376,7 +373,7 @@ function config.loadkernel(other_kernel)
|
|||
-- Use our cached module_path, so we don't end up with multiple
|
||||
-- automatically added kernel paths to our final module_path
|
||||
local module_path = config.module_path
|
||||
local res = nil
|
||||
local res
|
||||
|
||||
if other_kernel ~= nil then
|
||||
kernel = other_kernel
|
||||
|
@ -385,7 +382,7 @@ function config.loadkernel(other_kernel)
|
|||
-- then try load with module_path=${kernel}
|
||||
local paths = {"/boot/" .. kernel, kernel}
|
||||
|
||||
for k,v in pairs(paths) do
|
||||
for _, v in pairs(paths) do
|
||||
loader.setenv("module_path", v)
|
||||
res = load_bootfile()
|
||||
|
||||
|
@ -452,7 +449,7 @@ end
|
|||
|
||||
function config.loadelf()
|
||||
local kernel = config.kernel_selected or config.kernel_loaded
|
||||
local loaded = false
|
||||
local loaded
|
||||
|
||||
print("Loading kernel...")
|
||||
loaded = config.loadkernel(kernel)
|
||||
|
|
|
@ -200,7 +200,6 @@ function core.bootenvList()
|
|||
local bootenv_count = tonumber(loader.getenv("bootenvs_count"))
|
||||
local bootenvs = {}
|
||||
local curenv
|
||||
local curenv_idx = 0
|
||||
local envcount = 0
|
||||
local unique = {}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ local fbsd_logo
|
|||
local beastie_color
|
||||
local beastie
|
||||
local fbsd_logo_v
|
||||
local orb_color
|
||||
local orb
|
||||
local none
|
||||
local none_shifted = false
|
||||
|
@ -178,7 +179,7 @@ drawer.menu_name_handlers = {
|
|||
-- This is designed so that everything, including menu separators, may
|
||||
-- have their names derived differently. The default action for entry
|
||||
-- types not specified here is to use entry.name directly.
|
||||
[core.MENU_SEPARATOR] = function(drawing_menu, entry)
|
||||
[core.MENU_SEPARATOR] = function(_, entry)
|
||||
if entry.name ~= nil then
|
||||
if type(entry.name) == "function" then
|
||||
return entry.name()
|
||||
|
@ -187,7 +188,7 @@ drawer.menu_name_handlers = {
|
|||
end
|
||||
return ""
|
||||
end,
|
||||
[core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry)
|
||||
[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
|
||||
local carid = entry.carousel_id
|
||||
local caridx = config.getCarouselIndex(carid)
|
||||
local choices = entry.items
|
||||
|
@ -263,8 +264,8 @@ function drawer.drawscreen(menu_opts)
|
|||
end
|
||||
|
||||
function drawer.drawmenu(m)
|
||||
x = drawer.menu_position.x
|
||||
y = drawer.menu_position.y
|
||||
local x = drawer.menu_position.x
|
||||
local y = drawer.menu_position.y
|
||||
|
||||
-- print the menu and build the alias table
|
||||
local alias_table = {}
|
||||
|
@ -288,7 +289,7 @@ function drawer.drawmenu(m)
|
|||
-- fill the alias table
|
||||
alias_table[tostring(entry_num)] = e
|
||||
if e.alias ~= nil then
|
||||
for n, a in ipairs(e.alias) do
|
||||
for _, a in ipairs(e.alias) do
|
||||
alias_table[a] = e
|
||||
end
|
||||
end
|
||||
|
@ -303,10 +304,10 @@ end
|
|||
|
||||
|
||||
function drawer.drawbox()
|
||||
x = drawer.box_pos_dim.x
|
||||
y = drawer.box_pos_dim.y
|
||||
w = drawer.box_pos_dim.w
|
||||
h = drawer.box_pos_dim.h
|
||||
local x = drawer.box_pos_dim.x
|
||||
local y = drawer.box_pos_dim.y
|
||||
local w = drawer.box_pos_dim.w
|
||||
local h = drawer.box_pos_dim.h
|
||||
|
||||
local hl = string.char(0xCD)
|
||||
local vl = string.char(0xBA)
|
||||
|
|
|
@ -27,16 +27,15 @@
|
|||
-- $FreeBSD$
|
||||
--
|
||||
|
||||
local cli = require("cli")
|
||||
require("cli")
|
||||
local config = require("config")
|
||||
local menu = require("menu")
|
||||
local password = require("password")
|
||||
local local_module
|
||||
|
||||
local result, errstr, errnoval = lfs.attributes("/boot/lua/local.lua")
|
||||
local result, _, _ = lfs.attributes("/boot/lua/local.lua")
|
||||
-- Effectively discard any errors; we'll just act if it succeeds.
|
||||
if result ~= nil then
|
||||
local_module = require("local")
|
||||
require("local")
|
||||
end
|
||||
|
||||
config.load()
|
||||
|
|
|
@ -59,11 +59,11 @@ menu.handlers = {
|
|||
-- continue or not. The return value may be omitted if this entry should
|
||||
-- have no bearing on whether we continue or not, indicating that we
|
||||
-- should just continue after execution.
|
||||
[core.MENU_ENTRY] = function(current_menu, entry)
|
||||
[core.MENU_ENTRY] = function(_, entry)
|
||||
-- run function
|
||||
entry.func()
|
||||
end,
|
||||
[core.MENU_CAROUSEL_ENTRY] = function(current_menu, entry)
|
||||
[core.MENU_CAROUSEL_ENTRY] = function(_, entry)
|
||||
-- carousel (rotating) functionality
|
||||
local carid = entry.carousel_id
|
||||
local caridx = config.getCarouselIndex(carid)
|
||||
|
@ -77,11 +77,11 @@ menu.handlers = {
|
|||
entry.func(caridx, choices[caridx], choices)
|
||||
end
|
||||
end,
|
||||
[core.MENU_SUBMENU] = function(current_menu, entry)
|
||||
[core.MENU_SUBMENU] = function(_, entry)
|
||||
-- recurse
|
||||
return menu.run(entry.submenu)
|
||||
end,
|
||||
[core.MENU_RETURN] = function(current_menu, entry)
|
||||
[core.MENU_RETURN] = function(_, entry)
|
||||
-- allow entry to have a function/side effect
|
||||
if entry.func ~= nil then
|
||||
entry.func()
|
||||
|
@ -122,7 +122,7 @@ menu.boot_environments = {
|
|||
bootenv_name .. " (" .. idx .. " of " ..
|
||||
#all_choices .. ")"
|
||||
end,
|
||||
func = function(idx, choice, all_choices)
|
||||
func = function(_, choice, _)
|
||||
bootenvSet(choice)
|
||||
end,
|
||||
alias = {"a", "A"},
|
||||
|
@ -312,7 +312,7 @@ menu.welcome = {
|
|||
kernel_name .. " (" .. idx .. " of " ..
|
||||
#all_choices .. ")"
|
||||
end,
|
||||
func = function(idx, choice, all_choices)
|
||||
func = function(_, choice, _)
|
||||
config.selectkernel(choice)
|
||||
end,
|
||||
alias = {"k", "K"}
|
||||
|
@ -361,7 +361,7 @@ function menu.run(m)
|
|||
if m == menu.default then
|
||||
autoboot_key = menu.autoboot()
|
||||
end
|
||||
cont = true
|
||||
local cont = true
|
||||
while cont do
|
||||
local key = autoboot_key or io.getchar()
|
||||
autoboot_key = nil
|
||||
|
|
|
@ -38,7 +38,7 @@ function password.read()
|
|||
local n = 0
|
||||
|
||||
while true do
|
||||
ch = io.getchar()
|
||||
local ch = io.getchar()
|
||||
if ch == core.KEY_ENTER then
|
||||
break
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue