[latex3-commits] [git/LaTeX3-latex3-latex2e] newluacmd: Add \newluacmd & \newprotectedluacmd (f1dd7ffd)

Marcel Fabian Krüger tex at 2krueger.de
Mon Dec 27 06:45:24 CET 2021


Repository : https://github.com/latex3/latex2e
On branch  : newluacmd
Link       : https://github.com/latex3/latex2e/commit/f1dd7ffd556e191d0650e5b90746ce8fbbab45e9

>---------------------------------------------------------------

commit f1dd7ffd556e191d0650e5b90746ce8fbbab45e9
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Mon Mar 22 16:11:03 2021 +0100

    Add \newluacmd & \newprotectedluacmd


>---------------------------------------------------------------

f1dd7ffd556e191d0650e5b90746ce8fbbab45e9
 base/ltluatex.dtx                           | 29 ++++++++++++++++++++++++++++-
 base/ltoutenc.dtx                           |  5 ++---
 base/ltshipout.dtx                          |  5 ++---
 base/testfiles/github-0479-often.luatex.tlg |  1 -
 base/testfiles/tlb-rollback-005.luatex.tlg  |  1 -
 5 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/base/ltluatex.dtx b/base/ltluatex.dtx
index 687ab5ae..b033cb71 100644
--- a/base/ltluatex.dtx
+++ b/base/ltluatex.dtx
@@ -28,7 +28,7 @@
 \ProvidesFile{ltluatex.dtx}
 %</driver>
 %<*tex>
-[2021/11/17 v1.1w
+[2021/12/27 v1.1x
 %</tex>
 %<plain>  LuaTeX support for plain TeX (core)
 %<*tex>
@@ -120,6 +120,17 @@
 % tables from $1$ so |\luafunction0| is not available).
 %
 % \noindent
+% \DescribeMacro{\newluacmd}
+% |\newluadef{|\meta{function}|}|\\
+% Like \cs{newluafunction}, but defines the command using \cs{luadef}
+% instead of just assigning an integer.
+%
+% \noindent
+% \DescribeMacro{\newprotectedluacmd}
+% |\newluadef{|\meta{function}|}|\\
+% Like \cs{newluacmd}, but the defined command is not expandable.
+%
+% \noindent
 % \DescribeMacro{\newwhatsit}
 % |\newwhatsit{|\meta{whatsit}|}|\\
 % Defines a custom \cs{whatsit}, indexed from~$1$.
@@ -722,6 +733,22 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\newluacmd, \newprotectedluacmd}
+% \changes{v1.1x}{2021/12/27}{Macros added}
+%   Additionally two variants are provided to make the passed control
+%   sequence call the function directly.
+%    \begin{macrocode}
+\def\newluacmd{%
+  \e at alloc\luafunction\luadef
+    \e at alloc@luafunction at count\m at ne\e at alloc@top
+}
+\def\newprotectedluacmd{%
+  \e at alloc\luafunction{\protected\luadef}
+    \e at alloc@luafunction at count\m at ne\e at alloc@top
+}
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Custom whatsits}
 %
 % \begin{macro}{\newwhatsit}
diff --git a/base/ltoutenc.dtx b/base/ltoutenc.dtx
index b83907fc..1887ad32 100644
--- a/base/ltoutenc.dtx
+++ b/base/ltoutenc.dtx
@@ -2949,14 +2949,14 @@
         \endgroup
       }
     \else
-      \newluafunction\@remove at tlig@@@@
+      \newprotectedluacmd\@remove at tlig@@@
 %    \end{macrocode}
 % Now we can define the function. Mostly we just have to insert a protected glyph
 % node, which is a glyph node with subtype 256. But we have to keep track of the
 % current mode to avoid inserting the glyph into a vlist.
 %    \begin{macrocode}
       \now at and@everyjob{\directlua{
-        local rawchar_func = token.create'@remove at tlig@@@@'.index
+        local rawchar_func = token.create'@remove at tlig@@@'.index
         local forcehmode = tex.forcehmode
         local put_next = token.put_next
         local glyph_id = node.id'glyph'
@@ -2972,7 +2972,6 @@
           n.char = token.scan_int()
           return node.write(n)
         end
-        token.set_lua('@remove at tlig@@@', rawchar_func, 'global', 'protected')
       }}
 %    \end{macrocode}
 % Now \verb+\remove at tlig+ can be implemented almost as in XeTeX.
diff --git a/base/ltshipout.dtx b/base/ltshipout.dtx
index de64c6ed..af8a7c8f 100644
--- a/base/ltshipout.dtx
+++ b/base/ltshipout.dtx
@@ -734,13 +734,13 @@
 %    \begin{macrocode}
 \sys_if_engine_luatex:TF
   {
-    \newluafunction \@@_finalize_box:
+    \newprotectedluacmd \@@_finalize_box:
     \exp_args:Nx \everyjob {
       \exp_not:V \everyjob
       \exp_not:N \lua_now:n {
         luatexbase.create_callback('pre_shipout_filter', 'list')
         local~call, getbox, setbox = luatexbase.call_callback, tex.getbox, tex.setbox~
-        lua.get_functions_table()[\the \@@_finalize_box:] = function()
+        lua.get_functions_table()[\the \allocationnumber] = function()
           local~head = getbox(\the \l_shipout_box)
           local~result = call('pre_shipout_filter', head)
           if~not (result == head) then~
@@ -749,7 +749,6 @@
         end
       }
     }
-    \protected \luadef \@@_finalize_box: \the \@@_finalize_box:
   } {
     \cs_set_eq:NN \@@_finalize_box: \scan_stop:
   }
diff --git a/base/testfiles/github-0479-often.luatex.tlg b/base/testfiles/github-0479-often.luatex.tlg
index 241f9932..da2f19a0 100644
--- a/base/testfiles/github-0479-often.luatex.tlg
+++ b/base/testfiles/github-0479-often.luatex.tlg
@@ -616,7 +616,6 @@ Already applied: [....-..-..] Disable packages on input line ....
 Applying: [....-..-..] 2e tmp interfaces on input line ....
 Already applied: [....-..-..] 2e tmp interfaces on input line ....
 Applying: [....-..-..] Hook management (shipout) on input line ....
-\__shipout_finalize_box:=\luafunction...
 Already applied: [....-..-..] Hook management (shipout) on input line ....
 Applying: [....-..-..] atenddvi emulation on input line ....
 Already applied: [....-..-..] atenddvi emulation on input line ....
diff --git a/base/testfiles/tlb-rollback-005.luatex.tlg b/base/testfiles/tlb-rollback-005.luatex.tlg
index 2804377f..9a8bb0cd 100644
--- a/base/testfiles/tlb-rollback-005.luatex.tlg
+++ b/base/testfiles/tlb-rollback-005.luatex.tlg
@@ -620,7 +620,6 @@ Already applied: [....-..-..] Disable packages on input line ....
 Applying: [....-..-..] 2e tmp interfaces on input line ....
 Already applied: [....-..-..] 2e tmp interfaces on input line ....
 Applying: [....-..-..] Hook management (shipout) on input line ....
-\__shipout_finalize_box:=\luafunction...
 Already applied: [....-..-..] Hook management (shipout) on input line ....
 Applying: [....-..-..] atenddvi emulation on input line ....
 Already applied: [....-..-..] atenddvi emulation on input line ....





More information about the latex3-commits mailing list.