svn commit: r329640 - head/stand/lua

Kyle Evans kevans at FreeBSD.org
Tue Feb 20 14:36:29 UTC 2018


Author: kevans
Date: Tue Feb 20 14:36:28 2018
New Revision: 329640
URL: https://svnweb.freebsd.org/changeset/base/329640

Log:
  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.

Modified:
  head/stand/lua/drawer.lua
  head/stand/lua/menu.lua
  head/stand/lua/screen.lua

Modified: head/stand/lua/drawer.lua
==============================================================================
--- head/stand/lua/drawer.lua	Tue Feb 20 10:52:07 2018	(r329639)
+++ head/stand/lua/drawer.lua	Tue Feb 20 14:36:28 2018	(r329640)
@@ -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;
@@ -332,15 +341,6 @@ function drawer.drawbrand()
 		graphic = fbsd_logo;
 	end
 	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()

Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua	Tue Feb 20 10:52:07 2018	(r329639)
+++ head/stand/lua/menu.lua	Tue Feb 20 14:36:28 2018	(r329640)
@@ -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
@@ -459,16 +469,6 @@ function menu.autoboot()
 	until time <= 0;
 	core.boot();
 
-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;

Modified: head/stand/lua/screen.lua
==============================================================================
--- head/stand/lua/screen.lua	Tue Feb 20 10:52:07 2018	(r329639)
+++ head/stand/lua/screen.lua	Tue Feb 20 14:36:28 2018	(r329640)
@@ -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("%.");
 


More information about the svn-src-head mailing list