Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Apr 2015 05:55:04 +0000 (UTC)
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r280947 - projects/lua-bootloader/sys/boot/common
Message-ID:  <201504010555.t315t4kJ067097@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rpaulo
Date: Wed Apr  1 05:55:03 2015
New Revision: 280947
URL: https://svnweb.freebsd.org/changeset/base/280947

Log:
  Parse lines as loader commands if we could not parse it as Lua.
  
  This lets us type 'reset', 'boot', etc. in the interpreter.  Forth has
  an advantage here because it compiles the loader commands as verbs, so
  it automatically executes Forth verbs (functions).
  
  The loader command syntax is very different from Lua syntax, so this
  workaround should be good enough.

Modified:
  projects/lua-bootloader/sys/boot/common/interp_lua.c

Modified: projects/lua-bootloader/sys/boot/common/interp_lua.c
==============================================================================
--- projects/lua-bootloader/sys/boot/common/interp_lua.c	Wed Apr  1 05:46:57 2015	(r280946)
+++ projects/lua-bootloader/sys/boot/common/interp_lua.c	Wed Apr  1 05:55:03 2015	(r280947)
@@ -88,12 +88,26 @@ interp_lua_run(void *data, const char *l
 	struct interp_lua_softc	*softc;
 	int argc, ret;
 	char **argv;
+	char loader_line[128];
+	int status;
+	int len;
 
 	softc = data;
 	luap = softc->luap;
-	LDBG("running line...");
-	if (ldo_string(luap, line, strlen(line)) != 0)
-		printf("failed to parse \'%s\'\n", line);
+	LDBG("executing line...");
+	if ((status = ldo_string(luap, line, strlen(line))) != 0) {
+		/*
+		 * If we could not parse the line as Lua syntax,
+		 * try parsing it as a loader command.
+		 */
+		len = snprintf(loader_line, sizeof(loader_line),
+		    "loader.perform(\"%s\")", line);
+		if (len > 0)
+			status = ldo_string(luap, loader_line,
+			    len + 1);
+	}
+	if (status != 0)
+		printf("Failed to parse \'%s\'\n", line);
 
 	return (0);
 }



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