Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Feb 2018 14:45:58 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329641 - head/stand/lua
Message-ID:  <201802201445.w1KEjwOa072782@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Tue Feb 20 14:45:58 2018
New Revision: 329641
URL: https://svnweb.freebsd.org/changeset/base/329641

Log:
  stand/lua: Consistently organize modules
  
  We follow pretty closely the following structure of a module:
  
  1. Copyright notice
  2. Module requires
  3. Module local declarations
  4. Module local definitions
  5. Module exports
  6. return
  
  Re-organize the one-offs (config/drawer) and denote the start of module
  exports with a comment.

Modified:
  head/stand/lua/color.lua
  head/stand/lua/config.lua
  head/stand/lua/core.lua
  head/stand/lua/drawer.lua
  head/stand/lua/menu.lua
  head/stand/lua/password.lua
  head/stand/lua/screen.lua

Modified: head/stand/lua/color.lua
==============================================================================
--- head/stand/lua/color.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/color.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -30,6 +30,7 @@ local core = require("core");
 
 local color = {};
 
+-- Module exports
 color.BLACK   = 0;
 color.RED     = 1;
 color.GREEN   = 2;

Modified: head/stand/lua/config.lua
==============================================================================
--- head/stand/lua/config.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/config.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -28,52 +28,9 @@
 --
 
 local config = {};
--- Which variables we changed
-config.env_changed = {};
--- Values to restore env to (nil to unset)
-config.env_restore = {};
 
 local modules = {};
 
-function config.restoreEnv()
-	for k, v in pairs(config.env_changed) do
-		local restore_value = config.env_restore[k];
-		if (restore_value ~= nil) then
-			loader.setenv(k, restore_value);
-		else
-			loader.unsetenv(k);
-		end
-	end
-
-	config.env_changed = {};
-	config.env_restore = {};
-end
-
-function config.setenv(k, v)
-	-- Do we need to track this change?
-	if (config.env_changed[k] == nil) then
-		config.env_changed[k] = true;
-		config.env_restore[k] = loader.getenv(k);
-	end
-
-	return loader.setenv(k, v);
-end
-
-function config.setKey(k, n, v)
-	if (modules[k] == nil) then
-		modules[k] = {};
-	end
-	modules[k][n] = v;
-end
-
-function config.lsModules()
-	print("== Listing modules");
-	for k, v in pairs(modules) do
-		print(k, v.load);
-	end
-	print("== List of modules ended");
-end
-
 local pattern_table = {
 	[1] = {
 		str = "^%s*(#.*)",
@@ -162,6 +119,52 @@ local pattern_table = {
 	}
 };
 
+-- Module exports
+-- Which variables we changed
+config.env_changed = {};
+-- Values to restore env to (nil to unset)
+config.env_restore = {};
+
+function config.restoreEnv()
+	for k, v in pairs(config.env_changed) do
+		local restore_value = config.env_restore[k];
+		if (restore_value ~= nil) then
+			loader.setenv(k, restore_value);
+		else
+			loader.unsetenv(k);
+		end
+	end
+
+	config.env_changed = {};
+	config.env_restore = {};
+end
+
+function config.setenv(k, v)
+	-- Do we need to track this change?
+	if (config.env_changed[k] == nil) then
+		config.env_changed[k] = true;
+		config.env_restore[k] = loader.getenv(k);
+	end
+
+	return loader.setenv(k, v);
+end
+
+function config.setKey(k, n, v)
+	if (modules[k] == nil) then
+		modules[k] = {};
+	end
+	modules[k][n] = v;
+end
+
+function config.lsModules()
+	print("== Listing modules");
+	for k, v in pairs(modules) do
+		print(k, v.load);
+	end
+	print("== List of modules ended");
+end
+
+
 function config.isValidComment(c)
 	if (c ~= nil) then
 		local s = c:match("^%s*#.*");
@@ -432,6 +435,5 @@ function config.loadelf()
 		print("Could not load one or more modules!");
 	end
 end
-
 
 return config;

Modified: head/stand/lua/core.lua
==============================================================================
--- head/stand/lua/core.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/core.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -30,6 +30,7 @@ local config = require('config');
 
 local core = {};
 
+-- Module exports
 -- Commonly appearing constants
 core.KEY_BACKSPACE	= 8;
 core.KEY_ENTER		= 13;

Modified: head/stand/lua/drawer.lua
==============================================================================
--- head/stand/lua/drawer.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/drawer.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -59,29 +59,6 @@ local shift_brand_text = function(shift)
 	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.
-	-- 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 call and use entry.name().
-	[core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry)
-		local carid = entry.carousel_id;
-		local caridx = menu.getCarouselIndex(carid);
-		local choices = entry.items();
-
-		if (#choices < caridx) then
-			caridx = 1;
-		end
-		return entry.name(caridx, choices[caridx], choices);
-	end,
-};
-
-drawer.brand_position = {x = 2, y = 1};
-drawer.logo_position = {x = 46, y = 1};
-drawer.menu_position = {x = 6, y = 11};
-drawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11};
-
 fbsd_logo = {
 	"  ______               ____   _____ _____  ",
 	" |  ____|             |  _ \\ / ____|  __ \\ ",
@@ -189,6 +166,30 @@ orb = {
 };
 
 none = {""};
+
+-- Module exports
+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.
+	-- 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 call and use entry.name().
+	[core.MENU_CAROUSEL_ENTRY] = function(drawing_menu, entry)
+		local carid = entry.carousel_id;
+		local caridx = menu.getCarouselIndex(carid);
+		local choices = entry.items();
+
+		if (#choices < caridx) then
+			caridx = 1;
+		end
+		return entry.name(caridx, choices[caridx], choices);
+	end,
+};
+
+drawer.brand_position = {x = 2, y = 1};
+drawer.logo_position = {x = 46, y = 1};
+drawer.menu_position = {x = 6, y = 11};
+drawer.box_pos_dim = {x = 3, y = 10, w = 41, h = 11};
 
 drawer.branddefs = {
 	-- Indexed by valid values for loader_brand in loader.conf(5). Valid

Modified: head/stand/lua/menu.lua
==============================================================================
--- head/stand/lua/menu.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/menu.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -51,7 +51,7 @@ local OnOff = function(str, b)
 	end
 end
 
-
+-- Module exports
 menu.handlers = {
 	-- Menu handlers take the current menu and selected entry as parameters,
 	-- and should return a boolean indicating whether execution should

Modified: head/stand/lua/password.lua
==============================================================================
--- head/stand/lua/password.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/password.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -32,6 +32,7 @@ local screen = require("screen");
 
 local password = {};
 
+-- Module exports
 function password.read()
 	local str = "";
 	local n = 0;

Modified: head/stand/lua/screen.lua
==============================================================================
--- head/stand/lua/screen.lua	Tue Feb 20 14:36:28 2018	(r329640)
+++ head/stand/lua/screen.lua	Tue Feb 20 14:45:58 2018	(r329641)
@@ -42,6 +42,7 @@ local intstring = function(num)
 	return str;
 end
 
+-- Module exports
 function screen.clear()
 	if (core.isSerialBoot()) then
 		return;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802201445.w1KEjwOa072782>