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

Marcel Fabian Krüger tex at 2krueger.de
Mon Nov 15 17:53:16 CET 2021


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

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

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

    Add \newluacmd & \newprotectedluacmd


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

87298469161b89d36d8788e764d48c4056c58045
 base/ltluatex.dtx                           | 27 +++++++++++++++++++++++++++
 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, 31 insertions(+), 8 deletions(-)

diff --git a/base/ltluatex.dtx b/base/ltluatex.dtx
index 258ac482..91df1068 100644
--- a/base/ltluatex.dtx
+++ b/base/ltluatex.dtx
@@ -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{v?.?}{2021/03/22}{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 61ea3818..1a1dd5f9 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 7f6555d1..ff8a7dc5 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~result = call('pre_shipout_filter', getbox(\the \l_shipout_box))
           if~not (result == true) then~
             setbox(\the \l_shipout_box, result~or~nil)
@@ -748,7 +748,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 7d561984..e3ac67be 100644
--- a/base/testfiles/github-0479-often.luatex.tlg
+++ b/base/testfiles/github-0479-often.luatex.tlg
@@ -609,7 +609,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 bdcc80a9..aaa45ff3 100644
--- a/base/testfiles/tlb-rollback-005.luatex.tlg
+++ b/base/testfiles/tlb-rollback-005.luatex.tlg
@@ -613,7 +613,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.