Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Dec 2020 21:38:58 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 4fd8afa474da - stable/12 - MFC: stand: liblua: add a pager module
Message-ID:  <202012272138.0BRLcwYG010807@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=4fd8afa474dab1d2389f8b54f7ba1b45bcf62823

commit 4fd8afa474dab1d2389f8b54f7ba1b45bcf62823
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2020-12-12 21:25:38 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2020-12-27 20:55:03 +0000

    MFC: stand: liblua: add a pager module
    
    This is nearly a 1:1 mapping of the pager API from libsa.  The only real
    difference is that pager.output() will accept any number of arguments and
    coerce all of them to strings for output using luaL_tolstring (i.e. the
    __tostring metamethod will be used).
    
    The only consumer planned at this time is the upcoming "show-module-options"
    implementation.
    
    (cherry picked from commit 0a0d522b368b31ec51611b798047a75b52855f39)
---
 stand/common/interp_lua.c |  1 +
 stand/liblua/Makefile     |  2 +-
 stand/liblua/lpager.c     | 89 +++++++++++++++++++++++++++++++++++++++++++++++
 stand/liblua/lutils.h     |  1 +
 4 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/stand/common/interp_lua.c b/stand/common/interp_lua.c
index 0a6035e7bb28..94001918e151 100644
--- a/stand/common/interp_lua.c
+++ b/stand/common/interp_lua.c
@@ -95,6 +95,7 @@ static const luaL_Reg loadedlibs[] = {
   {"io", luaopen_io},
   {"lfs", luaopen_lfs},
   {"loader", luaopen_loader},
+  {"pager", luaopen_pager},
   {NULL, NULL}
 };
 
diff --git a/stand/liblua/Makefile b/stand/liblua/Makefile
index 0f4047769b77..434268063158 100644
--- a/stand/liblua/Makefile
+++ b/stand/liblua/Makefile
@@ -23,7 +23,7 @@ SRCS+=	lauxlib.c lbaselib.c lstrlib.c loadlib.c
 #SRCS+=	lbitlib.c liolib.c lmathlib.c loslib.c ltablib.c
 
 # Our utilities.
-SRCS+=	lerrno.c lstd.c lutils.c
+SRCS+=	lerrno.c lpager.c lstd.c lutils.c
 
 .PATH:	${FLUASRC}/modules
 SRCS+=	lfs.c
diff --git a/stand/liblua/lpager.c b/stand/liblua/lpager.c
new file mode 100644
index 000000000000..910931e11d58
--- /dev/null
+++ b/stand/liblua/lpager.c
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2020 Kyle Evans <kevans@FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <lua.h>
+#include "lauxlib.h"
+
+/* Open the pager.  No arguments, no return value. */
+static int
+lpager_open(lua_State *L)
+{
+
+	pager_open();
+	return (0);
+}
+
+/*
+ * Output to the pager.  All arguments are interpreted as strings and passed to
+ * pager_output().  No return value.
+ */
+static int
+lpager_output(lua_State *L)
+{
+	const char *outstr;
+	int i;
+
+	for (i = 1; i <= lua_gettop(L); i++) {
+		outstr = luaL_tolstring(L,  i, NULL);
+		pager_output(outstr);
+		lua_pop(L, -1);
+	}
+
+	return (0);
+}
+
+/* Output to the pager from a file.  Takes a filename, no return value. */
+static int
+lpager_file(lua_State *L)
+{
+
+	return (pager_file(luaL_checkstring(L, 1)));
+}
+
+static int
+lpager_close(lua_State *L)
+{
+
+	pager_close();
+	return (0);
+}
+
+static const struct luaL_Reg pagerlib[] = {
+	{ "open", lpager_open },
+	{ "output", lpager_output },
+	{ "file", lpager_file },
+	{ "close", lpager_close },
+	{ NULL, NULL },
+};
+
+int
+luaopen_pager(lua_State *L)
+{
+	luaL_newlib(L, pagerlib);
+	return 1;
+}
diff --git a/stand/liblua/lutils.h b/stand/liblua/lutils.h
index 6d14807160e4..d7d968b705bb 100644
--- a/stand/liblua/lutils.h
+++ b/stand/liblua/lutils.h
@@ -30,3 +30,4 @@
 
 int	luaopen_loader(lua_State *);
 int	luaopen_io(lua_State *);
+int	luaopen_pager(lua_State *);



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