Maintainer sought for my power patches

"'Reuben Thomas' via lua-l" <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <CAOnWdojp+rpcYs2FCU7usYiU3-sY7zrENboJTioLEdCor09z2w@mail.gmail.com>
Dear all,

I realised recently that for some years I've spent more time simply
refreshing my "power patches" for successive releases of Lua than on all
other Lua programming combined. (These days I find I mostly use Python, and
it's been many years since I actively developed in Lua.)

Hence, I would like to find a new maintainer, or new maintainers, for these
patches for the Lua build system and front-end (i.e. lua.c).

The patches can be seen as a GitHub gist
<https://gist.github.com/rrthomas/699d9f2a933c0a19ab5d7b253117d8eb> (they
used to live on lua-users.org, but I find I can no longer edit it). I also
attach the current versions to this email.

There are two patches:

1. Add readline history loading/saving. Hey, [email protected], maybe you'd be
interested in this? I asked about it in the run-up to the 5.5 release, when
you were busy with that.

2. Add support for multi-version multi-arch installations. This is probably
mostly of interest to distro packagers. The patch changes the build system
to add architecture-specific and version-specific paths, so that Lua can be
installed in multiple versions and for multiple CPU architectures. The
current version of the patch uses a Debian-specific way to get the
architecture, but it could easily be made more generic.

The work involved in maintaining these patches is small: patch updates to
Lua usually require no changes, and minor version updates (the biggest sort
we've had for over 20 years!) usually require a bit of editing. (For
example, Lua 5.5 introduced support for dynamically loading readline, and
that induced bigger changes in the load/save readline history patch.)

Please contact me off-list if you're interested in maintaining these
patches.

On a personal note, I continue to find Lua inspiring both in technical and
narrative ways, even though I don't use it any longer, and I still check in
to see what's up from time to time!

All the best,

Reuben

-- 
Web: rrt.sc3d.org

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CAOnWdojp%2BrpcYs2FCU7usYiU3-sY7zrENboJTioLEdCor09z2w%40mail.gmail.com.
lua-5.5.1-multi_version_multi_arch.patch (text/x-patch, 12.2 KB)
diff --color --recursive --unified lua-5.5.1/Makefile lua-5.5.1-multi_version_multi_arch/Makefile
--- lua-5.5.1/Makefile	2026-07-14 19:25:18.000000000 +0100
+++ lua-5.5.1-multi_version_multi_arch/Makefile	2026-08-17 20:10:12.562327938 +0100
@@ -3,6 +3,8 @@
 
 # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
 
+DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
+
 # Your platform. See PLATS for possible values.
 PLAT= guess
 
@@ -11,16 +13,16 @@
 # You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with
 # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h.
 INSTALL_TOP= /usr/local
-INSTALL_BIN= $(INSTALL_TOP)/bin
-INSTALL_INC= $(INSTALL_TOP)/include
-INSTALL_LIB= $(INSTALL_TOP)/lib
-INSTALL_MAN= $(INSTALL_TOP)/man/man1
-INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V
-INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V
+INSTALL_BIN= $(INSTALL_TOP)/bin/$(DEB_HOST_MULTIARCH)
+INSTALL_INC= $(INSTALL_TOP)/include/lua$(V)
+INSTALL_LIB= $(INSTALL_TOP)/lib/$(DEB_HOST_MULTIARCH)
+INSTALL_MAN= $(INSTALL_TOP)/share/man/man1
+INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$(V)
+INSTALL_CMOD= $(INSTALL_TOP)/lib/$(DEB_HOST_MULTIARCH)/lua/$(V)
 
 # How to install. If your install program does not support "-p", then
 # you may have to run ranlib on the installed liblua.a.
-INSTALL= install -p
+INSTALL= libtool --mode=install install -p
 INSTALL_EXEC= $(INSTALL) -m 0755
 INSTALL_DATA= $(INSTALL) -m 0644
 #
@@ -39,9 +41,9 @@
 PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris
 
 # What to install.
-TO_BIN= lua luac
+TO_BIN= lua$(V) luac$(V)
 TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp
-TO_LIB= liblua.a
+TO_LIB= liblua$(V).la
 TO_MAN= lua.1 luac.1
 
 # Lua version and release.
@@ -52,7 +54,7 @@
 all:	$(PLAT)
 
 $(PLATS) help test clean:
-	@cd src && $(MAKE) $@
+	@cd src && $(MAKE) $@ INSTALL_LIB=$(INSTALL_LIB) DEB_HOST_MULTIARCH=$(DEB_HOST_MULTIARCH)
 
 install: dummy
 	cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
diff --color --recursive --unified lua-5.5.1/src/luaconf.h lua-5.5.1-multi_version_multi_arch/src/luaconf.h
--- lua-5.5.1/src/luaconf.h	2026-07-24 11:23:07.000000000 +0100
+++ lua-5.5.1-multi_version_multi_arch/src/luaconf.h	2026-08-17 20:39:19.112523939 +0100
@@ -242,19 +242,26 @@
 #else			/* }{ */
 
 #define LUA_ROOT	"/usr/local/"
+#define LUA_ROOT2	"/usr/"
 #define LUA_LDIR	LUA_ROOT "share/lua/" LUA_VDIR "/"
-#define LUA_CDIR	LUA_ROOT "lib/lua/" LUA_VDIR "/"
+#define LUA_LDIR2	LUA_ROOT2 "share/lua/" LUA_VDIR
+#define LUA_CDIR	LUA_ROOT "lib/" DEB_HOST_MULTIARCH "/lua/" LUA_VDIR
+#define LUA_CDIR2	LUA_ROOT2 "lib/" DEB_HOST_MULTIARCH "/lua/" LUA_VDIR
+#define LUA_CDIR3	LUA_ROOT2 "lib/lua/" LUA_VDIR
 
 #if !defined(LUA_PATH_DEFAULT)
 #define LUA_PATH_DEFAULT  \
 		LUA_LDIR "?.lua;"  LUA_LDIR "?/init.lua;" \
 		LUA_CDIR "?.lua;"  LUA_CDIR "?/init.lua;" \
+		LUA_LDIR2"?.lua;"  LUA_LDIR2 "?/init.lua;"     \
 		"./?.lua;" "./?/init.lua"
 #endif
 
 #if !defined(LUA_CPATH_DEFAULT)
 #define LUA_CPATH_DEFAULT \
-		LUA_CDIR "?.so;" LUA_CDIR "loadall.so;" "./?.so"
+		LUA_CDIR "?.so;" LUA_CDIR "loadall.so;" \
+		LUA_CDIR2 "?.so;" LUA_CDIR2 "loadall.so;" \
+		LUA_CDIR3 "?.so;" LUA_CDIR3 "loadall.so;" "./?.so"
 #endif
 
 #endif			/* } */
diff --color --recursive --unified lua-5.5.1/src/Makefile lua-5.5.1-multi_version_multi_arch/src/Makefile
--- lua-5.5.1/src/Makefile	2026-07-15 21:17:33.000000000 +0100
+++ lua-5.5.1-multi_version_multi_arch/src/Makefile	2026-08-17 20:32:09.652100534 +0100
@@ -6,8 +6,10 @@
 # Your platform. See PLATS for possible values.
 PLAT= guess
 
-CC= gcc -std=gnu99
-CFLAGS= -O2 -Wall -Wextra $(SYSCFLAGS) $(MYCFLAGS)
+V=5.5
+CC= libtool --mode=compile --tag=CC gcc -std=gnu99
+LD= libtool --mode=link --tag=CC gcc
+CFLAGS= -O2 -Wall -Wextra -DDEB_HOST_MULTIARCH='"$(DEB_HOST_MULTIARCH)"' $(SYSCFLAGS) $(MYCFLAGS)
 LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
 LIBS= -lm $(SYSLIBS) $(MYLIBS)
 
@@ -32,16 +34,19 @@
 
 PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris
 
-LUA_A=	liblua.a
-CORE_O=	lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o
-LIB_O=	lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o
+LUA_A=	liblua$(V).la
+CORE_O=	lapi.lo lcode.lo lctype.lo ldebug.lo ldo.lo ldump.lo lfunc.lo lgc.lo llex.lo \
+	lmem.lo lobject.lo lopcodes.lo lparser.lo lstate.lo lstring.lo ltable.lo \
+	ltm.lo lundump.lo lvm.lo lzio.lo
+LIB_O=	lauxlib.lo lbaselib.lo lcorolib.lo ldblib.lo liolib.lo \
+	lmathlib.lo loadlib.lo loslib.lo lstrlib.lo ltablib.lo lutf8lib.lo linit.lo
 BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
 
-LUA_T=	lua
-LUA_O=	lua.o
+LUA_T=	lua$(V)
+LUA_O=	lua.lo
 
-LUAC_T=	luac
-LUAC_O=	luac.o
+LUAC_T=	luac$(V)
+LUAC_O=	luac.lo
 
 ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
 ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
@@ -59,12 +64,13 @@
 $(LUA_A): $(BASE_O)
 	$(AR) $@ $(BASE_O)
 	$(RANLIB) $@
+	$(LD) -o $@ -version-info 0:0:0 -rpath $(INSTALL_LIB) $(BASE_O) -lm -ldl
 
 $(LUA_T): $(LUA_O) $(LUA_A)
-	$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+	$(LD) -o $@ $(LDFLAGS) -static -Wl,-E lua.o $(LUA_A) $(LIBS)
 
 $(LUAC_T): $(LUAC_O) $(LUA_A)
-	$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
+	$(LD) -o $@ $(LDFLAGS) -static luac.o lundump.o lopcodes.o $(LUA_A) -lm -ldl
 
 test:
 	./$(LUA_T) -v
@@ -145,88 +151,91 @@
 .PHONY: all $(PLATS) help test clean default o a depend echo
 
 # Compiler modules may use special flags.
-llex.o:
+llex.lo:
 	$(CC) $(CFLAGS) $(CMCFLAGS) -c llex.c
 
-lparser.o:
+lparser.lo:
 	$(CC) $(CFLAGS) $(CMCFLAGS) -c lparser.c
 
-lcode.o:
+lcode.lo:
 	$(CC) $(CFLAGS) $(CMCFLAGS) -c lcode.c
 
 # DO NOT DELETE
 
-lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+%.lo:%.c
+	$(CC) $(CFLAGS) -c $<
+
+lapi.lo: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \
  ltable.h lundump.h lvm.h
-lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h llimits.h
-lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+lauxlib.lo: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h llimits.h
+lbaselib.lo: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
+lcode.lo: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
  llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
  ldo.h lgc.h lstring.h ltable.h lvm.h lopnames.h
-lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+lcorolib.lo: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h
-ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
-ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+lctype.lo: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h
+ldblib.lo: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
+ldebug.lo: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \
  ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h
-ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+ldo.lo: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \
  lparser.h lstring.h ltable.h lundump.h lvm.h
-ldump.o: ldump.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+ldump.lo: ldump.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h lgc.h ltable.h lundump.h
-lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
+lfunc.lo: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
  llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h
-lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
+lgc.lo: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
  llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
-linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h llimits.h
-liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
-llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \
+linit.lo: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h llimits.h
+liolib.lo: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
+llex.lo: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \
  lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \
  lstring.h ltable.h
-lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+lmathlib.lo: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
+lmem.lo: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
  llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h
-loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+loadlib.lo: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \
+lobject.lo: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \
  ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \
  lvm.h
-lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h \
+lopcodes.lo: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h \
  lobject.h
-loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
-lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
+loslib.lo: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
+lparser.lo: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
  llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
  ldo.h lfunc.h lstring.h lgc.h ltable.h
-lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+lstate.lo: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \
  lstring.h ltable.h
-lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
+lstring.lo: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
  lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h
-lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+lstrlib.lo: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
+ltable.lo: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
  llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
-ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+ltablib.lo: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
+ltm.lo: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
  llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
-lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
-luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lapi.h llimits.h \
+lua.lo: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h llimits.h
+luac.lo: luac.c lprefix.h lua.h luaconf.h lauxlib.h lapi.h llimits.h \
  lstate.h lobject.h ltm.h lzio.h lmem.h ldebug.h lopcodes.h lopnames.h \
  lundump.h
-lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
+lundump.lo: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
  lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \
  ltable.h lundump.h
-lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
+lutf8lib.lo: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h \
  llimits.h
-lvm.o: lvm.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+lvm.lo: lvm.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \
  lstring.h ltable.h lvm.h ljumptab.h
-lzio.o: lzio.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
+lzio.lo: lzio.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
  lobject.h ltm.h lzio.h lmem.h
 
 # (end of Makefile)
lua-5.5.1-save_readline_history.patch (text/x-patch, 3.4 KB)
diff --color --recursive --unified lua-5.5.1/src/lua.c lua-5.5.1-save_readline_history/src/lua.c
--- lua-5.5.1/src/lua.c	2026-07-24 11:23:07.000000000 +0100
+++ lua-5.5.1-save_readline_history/src/lua.c	2026-08-17 20:52:21.588569535 +0100
@@ -449,6 +449,29 @@
 
 
 /*
+@@ LUA_HISTORY is the name of the environment variable that Lua checks
+@* to load its command-line history.
+** CHANGE it if you want a different name.
+*/
+#if !defined(LUA_HISTORY)
+#define LUA_HISTORY     "LUA_HISTORY"
+#endif
+
+
+/*
+@@ LUA_HISTORY_DEFAULT is the default path that Lua uses to look for
+@* the command-line history.
+*/
+#if defined(_WIN32)	/* { */
+#define LUA_HISTORY_DEFAULT \
+		"lua_history.txt"
+#else			/* }{ */
+#define LUA_HISTORY_DEFAULT \
+		".lua_history"
+#endif			/* } */
+
+
+/*
 ** * lua_initreadline initializes the readline system.
 ** * lua_readline defines how to show a prompt and then read a line from
 **   the standard input.
@@ -469,6 +492,8 @@
 #define lua_readline(buff,prompt)	((void)buff, readline(prompt))
 #define lua_saveline(line)	add_history(line)
 #define lua_freeline(line)	free(line)
+#define lua_readlinehistory(L,f)   ((void)L, (void)read_history(f))
+#define lua_writelinehistory(L,f)  ((void)L, (void)write_history(f))
 
 #else		/* }{ */
 /* use dynamically loaded readline (or nothing) */
@@ -481,6 +506,14 @@
 typedef void (*l_addhistT) (const char *string);
 static l_addhistT l_addhist = NULL;
 
+/* pointer to 'read_history' function (if any) */
+typedef void (*l_readhistT) (const char *filename);
+static l_readhistT l_readhist = NULL;
+
+/* pointer to 'write_history' function (if any) */
+typedef void (*l_writehistT) (const char *filename);
+static l_writehistT l_writehist = NULL;
+
 
 static char *lua_readline (char *buff, const char *prompt) {
   if (l_readline != NULL)  /* is there a 'readline'? */
@@ -500,6 +533,18 @@
 }
 
 
+static void lua_readlinehistory (char *filename) {
+  if (l_readhist != NULL)  /* is there a 'read_history'? */
+    (*l_readhist)(filename);  /* use it */
+}
+
+
+static void lua_freeline (char *line) {
+  if (l_writehist != NULL)  /* is there a 'write_history'? */
+    (*l_writehist)(line);  /* use it */
+}
+
+
 static void lua_freeline (char *line) {
   if (l_readline != NULL)  /* is there a 'readline'? */
     free(line);  /* free line created by it */
@@ -524,6 +569,8 @@
       *name = "lua";
     l_readline = cast(l_readlineT, cast_func(dlsym(lib, "readline")));
     l_addhist = cast(l_addhistT, cast_func(dlsym(lib, "add_history")));
+    l_readhist = cast(l_readhistT, cast_func(dlsym(lib, "read_history")));
+    l_writehist = cast(l_writehistT, cast_func(dlsym(lib, "write_history")));
     if (l_readline != NULL)  /* could load readline function? */
       return;  /* everything ok */
     /* else emit a warning */
@@ -698,6 +745,10 @@
 static void doREPL (lua_State *L) {
   int status;
   const char *oldprogname = progname;
+  const char *history_path = getenv(LUA_HISTORY);
+  if (history_path == NULL)  /* no environment variable? */
+    history_path = LUA_HISTORY_DEFAULT;  /* use default */
+  lua_readlinehistory(L, history_path);
   progname = NULL;  /* no 'progname' on errors in interactive mode */
   lua_initreadline(L);
   while ((status = loadline(L)) != -1) {
@@ -708,6 +759,7 @@
   }
   lua_settop(L, 0);  /* clear stack */
   lua_writeline();
+  lua_writelinehistory(L, history_path);
   progname = oldprogname;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.