stand/lua: Consistently declare local functions at module scope

Declare these adjacent to the local definitions at the top of the module,
and make sure they're actually declared local to pollute global namespace a
little bit less.
This commit is contained in:
kevans 2018-02-20 14:36:28 +00:00
parent d4ad49fd39
commit db50ad5b0c
3 changed files with 30 additions and 30 deletions

View File

@ -41,6 +41,24 @@ local orb;
local none;
local none_shifted = false;
local menu_entry_name = function(drawing_menu, entry)
local name_handler = drawer.menu_name_handlers[entry.entry_type];
if (name_handler ~= nil) then
return name_handler(drawing_menu, entry);
end
return entry.name();
end
local shift_brand_text = function(shift)
drawer.brand_position.x = drawer.brand_position.x + shift.x;
drawer.brand_position.y = drawer.brand_position.y + shift.y;
drawer.menu_position.x = drawer.menu_position.x + shift.x;
drawer.menu_position.y = drawer.menu_position.y + shift.y;
drawer.box_pos_dim.x = drawer.box_pos_dim.x + shift.x;
drawer.box_pos_dim.y = drawer.box_pos_dim.y + shift.y;
end
drawer.menu_name_handlers = {
-- Menu name handlers should take the menu being drawn and entry being
-- drawn as parameters, and return the name of the item.
@ -228,15 +246,6 @@ function drawer.drawscreen(menu_opts)
return drawer.drawmenu(menu_opts);
end
function menu_entry_name(drawing_menu, entry)
local name_handler = drawer.menu_name_handlers[entry.entry_type];
if (name_handler ~= nil) then
return name_handler(drawing_menu, entry);
end
return entry.name();
end
function drawer.drawmenu(m)
x = drawer.menu_position.x;
y = drawer.menu_position.y;
@ -334,15 +343,6 @@ function drawer.drawbrand()
drawer.draw(x, y, graphic);
end
function shift_brand_text(shift)
drawer.brand_position.x = drawer.brand_position.x + shift.x;
drawer.brand_position.y = drawer.brand_position.y + shift.y;
drawer.menu_position.x = drawer.menu_position.x + shift.x;
drawer.menu_position.y = drawer.menu_position.y + shift.y;
drawer.box_pos_dim.x = drawer.box_pos_dim.x + shift.x;
drawer.box_pos_dim.y = drawer.box_pos_dim.y + shift.y;
end
function drawer.drawlogo()
local x = tonumber(loader.getenv("loader_logo_x")) or
drawer.logo_position.x;

View File

@ -36,12 +36,22 @@ local drawer = require("drawer");
local menu = {};
local OnOff;
local skip;
local run;
local autoboot;
local carousel_choices = {};
local OnOff = function(str, b)
if (b) then
return str .. color.escapef(color.GREEN) .. "On" ..
color.escapef(color.WHITE);
else
return str .. color.escapef(color.RED) .. "off" ..
color.escapef(color.WHITE);
end
end
menu.handlers = {
-- Menu handlers take the current menu and selected entry as parameters,
-- and should return a boolean indicating whether execution should
@ -461,14 +471,4 @@ function menu.autoboot()
end
function OnOff(str, b)
if (b) then
return str .. color.escapef(color.GREEN) .. "On" ..
color.escapef(color.WHITE);
else
return str .. color.escapef(color.RED) .. "off" ..
color.escapef(color.WHITE);
end
end
return menu;

View File

@ -32,7 +32,7 @@ local core = require("core");
local screen = {};
-- XXX TODO: This should be fixed in the interpreter to not print decimals
function intstring(num)
local intstring = function(num)
local str = tostring(num);
local decimal = str:find("%.");