texlive[73808] Build/source/texk/web2c: LuaTeX: Add

commits+lscarso at tug.org commits+lscarso at tug.org
Sun Feb 9 18:59:02 CET 2025


Revision: 73808
          https://tug.org/svn/texlive?view=revision&revision=73808
Author:   lscarso
Date:     2025-02-09 18:59:01 +0100 (Sun, 09 Feb 2025)
Log Message:
-----------
LuaTeX: Add token.unchecked_put_next, support setting the environment with os.spawn, permit usage of the img module in texlua mode (thanks to tex at maxchernoff.ca)

Modified Paths:
--------------
    trunk/Build/source/texk/web2c/doc/luatex/luatex-lua.tex
    trunk/Build/source/texk/web2c/doc/luatex/luatex-tex.tex
    trunk/Build/source/texk/web2c/doc/luatex/luatex.pdf
    trunk/Build/source/texk/web2c/doc/luatex/luatex.tex
    trunk/Build/source/texk/web2c/luatexdir/ChangeLog
    trunk/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c
    trunk/Build/source/texk/web2c/luatexdir/lua/loslibext.c
    trunk/Build/source/texk/web2c/luatexdir/lua/luastuff.c
    trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
    trunk/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c

Modified: trunk/Build/source/texk/web2c/doc/luatex/luatex-lua.tex
===================================================================
--- trunk/Build/source/texk/web2c/doc/luatex/luatex-lua.tex	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/doc/luatex/luatex-lua.tex	2025-02-09 17:59:01 UTC (rev 73808)
@@ -570,6 +570,12 @@
     If the command ran ok, then the return value is the exit status of the
     command. Otherwise, it will return the two values \type {nil} and \type
     {error}.
+
+    \type {os.spawn()} takes an optional second argument, a table of key-value
+    pairs for the environment of the spawned process. Note that if you do pass
+    this table, it will be used as the \notabene {complete} environment for the
+    spawned process, so you'll likely want to start from \type {os.env} and add
+    or remove keys as needed.
 \stopitem
 
 \startitem

Modified: trunk/Build/source/texk/web2c/doc/luatex/luatex-tex.tex
===================================================================
--- trunk/Build/source/texk/web2c/doc/luatex/luatex-tex.tex	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/doc/luatex/luatex-tex.tex	2025-02-09 17:59:01 UTC (rev 73808)
@@ -1970,6 +1970,14 @@
      in \DVI\ output mode, if true abort run when the number of pages exceeds 65535. 
      This is the default behaviour. If false, the run goes on as is in \TEX.
 \NC \NR
+\NC \type{texlua_img} \NC boolean \NC
+\NC 
+     if true, allows access to the \type {img} library in \TEXLUA\ mode. If
+     false (the default), the \type {img} library is not available in \TEXLUA\
+     mode (as it was unconditionally for \LUATEX\ versions prior to 1.22.0).
+     Note that this setting is {\bf experimental} and subject to be removed at
+     any time, without notice.
+\NC \NR
 \LL
 \stoptabulate
 
@@ -2429,6 +2437,7 @@
 
 \libindex{get_next}
 \libindex{put_next}
+\libindex{unchecked_put_next}
 
 There is a (for now) experimental putter:
 
@@ -2444,7 +2453,12 @@
 \stoptyping
 
 When we scan \type {wxyz!} we get \type {yzwx!} back. The argument is either a table
-with tokens or a list of tokens. The \type {token.expand} function will trigger
+with tokens or a list of tokens. The new function \type {token.unchecked_put_next}
+has been added per request of the \LATEX\ team. It skips this error checking and
+follows a different code path. It assumes that a valid token user datum is
+passed and can crash the engine otherwise.
+
+The \type {token.expand} function will trigger
 expansion but what happens really depends on what you're doing where.
 
 \stopsubsection

Modified: trunk/Build/source/texk/web2c/doc/luatex/luatex.pdf
===================================================================
(Binary files differ)

Modified: trunk/Build/source/texk/web2c/doc/luatex/luatex.tex
===================================================================
--- trunk/Build/source/texk/web2c/doc/luatex/luatex.tex	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/doc/luatex/luatex.tex	2025-02-09 17:59:01 UTC (rev 73808)
@@ -73,7 +73,7 @@
 \startdocument
   [manual=Lua\TeX,
    status=stable,
-   version=1.21]
+   version=1.20]
 
 \startnotmode[*export]
     \component luatex-titlepage

Modified: trunk/Build/source/texk/web2c/luatexdir/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/ChangeLog	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/luatexdir/ChangeLog	2025-02-09 17:59:01 UTC (rev 73808)
@@ -1,7 +1,10 @@
-2025-02-05 Luigi Scarso <luigi.scarso at gmail.com>
+2025-02-09 Luigi Scarso <luigi.scarso at gmail.com>
 	* fixed shell-escape bypass (thanks to tex at maxchernoff.ca)
-
+	* Add token.unchecked_put_next, support setting the environment
+	  with os.spawn, permit usage of the img module in texlua mode
+	  (thanks to tex at maxchernoff.ca)
 	
+	
 2025-02-05 Luigi Scarso <luigi.scarso at gmail.com>
 	* add mathemptydisplaymode primitive, 
 	* fix nodes leak in end_graf (thanks to udifoglle at gmail.com)

Modified: trunk/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/luatexdir/lua/lnewtokenlib.c	2025-02-09 17:59:01 UTC (rev 73808)
@@ -336,6 +336,46 @@
     return 0;
 }
 
+inline static int unchecked_put_next(lua_State * L)
+{
+    int n = lua_gettop(L);
+    int i = 1;
+    halfword h = null;
+    halfword t = null;
+    halfword x = null;
+    lua_token *p ;
+    switch (n) {
+        case 0:
+            return 0;
+        case 1:
+            break;
+        default:
+            normal_error("token lib","only one table permitted in put_next");
+            return 0;
+    }
+    if (lua_type(L,1) == LUA_TTABLE) {
+        for (i = 1;; i++) {
+            lua_rawgeti(L, 1, i);
+            p = lua_touserdata(L, -1);
+            if (p == NULL) {
+                break;
+            }
+            fast_get_avail(x);
+            token_info(x) = token_info(p->token);
+            if (h == null) {
+                h = x;
+            } else {
+                token_link(t) = x;
+            }
+            t = x;
+            lua_pop(L, 1);
+        }
+    } 
+    begin_token_list(h,0);
+    lua_settop(L,n);
+    return 0;
+}
+
 static int run_scan_keyword(lua_State * L)
 {
     saved_tex_scanner texstate;
@@ -1409,6 +1449,7 @@
     { "scan_list", run_scan_list },
     /* writers */
     { "put_next", run_put_next },
+    { "unchecked_put_next", unchecked_put_next },
     { "expand", run_expand },
     /* getters */
     { "get_command", lua_tokenlib_get_command },

Modified: trunk/Build/source/texk/web2c/luatexdir/lua/loslibext.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/lua/loslibext.c	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/luatexdir/lua/loslibext.c	2025-02-09 17:59:01 UTC (rev 73808)
@@ -516,8 +516,8 @@
     char **cmdline = NULL;
     char **envblock = NULL;
     int i;
-
-    if (lua_gettop(L) != 1) {
+    int top = lua_gettop(L);
+    if (top != 1 && top != 2) {
         lua_pushnil(L);
         lua_pushliteral(L, "invalid arguments passed");
         return 2;
@@ -533,6 +533,26 @@
     } else if (lua_type(L, 1) == LUA_TTABLE) {
         cmdline = do_flatten_command(L, &runcmd);
     }
+    /* Allow setting the environment */
+    if (restrictedshell == 0 && top == 2 && lua_istable(L, 2)) {
+        const char *key, *val;
+        char *value;
+        int size = 0;
+        lua_pushnil(L);
+        while (lua_next(L, 2) != 0) {
+            if (lua_type(L, -2) == LUA_TSTRING &&
+                lua_type(L, -1) == LUA_TSTRING) {
+                key = lua_tostring(L, -2);
+                val = lua_tostring(L, -1);
+                value = xmalloc((unsigned) (strlen(key) + strlen(val) + 2));
+                sprintf(value, "%s=%s", key, val);
+                envblock = xreallocarray(envblock, char*, size++ + 1);
+                envblock[size] = value;
+            }
+            lua_pop(L, 1);
+        }
+        envblock[size++] = NULL;
+    }
     /* If restrictedshell == 0, any command is allowed. */
     /* this is a little different from \write18/ os.execute processing
      * because it does not test for commands with fixed arguments,

Modified: trunk/Build/source/texk/web2c/luatexdir/lua/luastuff.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/lua/luastuff.c	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/luatexdir/lua/luastuff.c	2025-02-09 17:59:01 UTC (rev 73808)
@@ -389,9 +389,7 @@
     luaopen_pdf(L);
     luaopen_pdfe(L);
     luaopen_pdfscanner(L);
-    if (!lua_only) {
-        luaopen_img(L);
-    }
+    luaopen_img(L);
     lua_createtable(L, 0, 0);
     lua_setglobal(L, "texconfig");
     Luas = L;

Modified: trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/luatexdir/luatex_svnversion.h	2025-02-09 17:59:01 UTC (rev 73808)
@@ -1,4 +1,4 @@
 #ifndef luatex_svn_revision_h
 #define luatex_svn_revision_h
-#define luatex_svn_revision 7660
+#define luatex_svn_revision 7661
 #endif

Modified: trunk/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c
===================================================================
--- trunk/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c	2025-02-09 17:56:55 UTC (rev 73807)
+++ trunk/Build/source/texk/web2c/luatexdir/pdf/pdfgen.c	2025-02-09 17:59:01 UTC (rev 73808)
@@ -1558,8 +1558,14 @@
     output_mode o_mode;
     const char *m = NULL;
     if (lua_only) {
-        normal_error("lua only","no backend present, needed for what you asked for");
-        return ;
+        boolean texlua_img = false;
+        get_lua_boolean("texconfig", "texlua_img", &texlua_img);
+        if (texlua_img) {
+            /* Ok, lets hope that you know what you are doing! */
+        } else {
+            normal_error("lua only","no backend present, needed for what you asked for");
+            return ;
+        }
     }
     if (output_mode_used == OMODE_NONE)
         o_mode = get_o_mode();



More information about the tex-live-commits mailing list.