Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Feb 2018 17:28:59 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329643 - head/stand/liblua
Message-ID:  <201802201728.w1KHSxZR054659@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Tue Feb 20 17:28:59 2018
New Revision: 329643
URL: https://svnweb.freebsd.org/changeset/base/329643

Log:
  Implement loader.command
  
  This is just like loader.perform, except it takes pre-parsed arguments.
  
  Review: https://reviews.freebsd.org/D14448

Modified:
  head/stand/liblua/lutils.c

Modified: head/stand/liblua/lutils.c
==============================================================================
--- head/stand/liblua/lutils.c	Tue Feb 20 14:59:29 2018	(r329642)
+++ head/stand/liblua/lutils.c	Tue Feb 20 17:28:59 2018	(r329643)
@@ -34,7 +34,32 @@ __FBSDID("$FreeBSD$");
 #include "lutils.h"
 #include "bootstrap.h"
 
+/*
+ * Like loader.perform, except args are passed already parsed
+ * on the stack.
+ */
 static int
+lua_command(lua_State *L)
+{
+	int	i;
+	int	res = 1;
+	int 	argc = lua_gettop(L);
+	char	**argv;
+
+	argv = malloc(sizeof(char *) * (argc + 1));
+	if (argv == NULL)
+		return 0;
+	for (i = 0; i < argc; i++)
+		argv[i] = (char *)(intptr_t)luaL_checkstring(L, i + 1);
+	argv[argc] = NULL;
+	res = interp_builtin_cmd(argc, argv);
+	free(argv);
+	lua_pushinteger(L, res);
+
+	return 1;
+}
+
+static int
 lua_perform(lua_State *L)
 {
 	int	argc;
@@ -213,6 +238,7 @@ lua_readfile(lua_State *L)
 #define REG_SIMPLE(n)	{ #n, lua_ ## n }
 static const struct luaL_Reg loaderlib[] = {
 	REG_SIMPLE(delay),
+	REG_SIMPLE(command),
 	REG_SIMPLE(getenv),
 	REG_SIMPLE(perform),
 	REG_SIMPLE(printc),



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