[latex3-commits] [git/LaTeX3-latex3-latex2e] develop: Add ltnews entry for \luacmd (c12d062a)

Marcel Fabian Krüger tex at 2krueger.de
Thu Feb 24 06:16:27 CET 2022


Repository : https://github.com/latex3/latex2e
On branch  : develop
Link       : https://github.com/latex3/latex2e/commit/c12d062a61f187a7e47535a4edeed6bccb543a3f

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

commit c12d062a61f187a7e47535a4edeed6bccb543a3f
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Thu Feb 24 06:16:27 2022 +0100

    Add ltnews entry for \luacmd


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

c12d062a61f187a7e47535a4edeed6bccb543a3f
 base/doc/ltnews35.tex | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/base/doc/ltnews35.tex b/base/doc/ltnews35.tex
index e0b7e39d..f87d5c55 100644
--- a/base/doc/ltnews35.tex
+++ b/base/doc/ltnews35.tex
@@ -316,6 +316,40 @@ layer)) which was also used in the example above.
 
 
 
+\subsection{Better allocator for Lua command ids}
+
+In \LuaTeX\ we already had the \cs{newluafunction} macro which allocates
+a Lua function identifier which can be used to define commands
+with \cs{luadef}. But this always required two steps: \cs{newluafunction}
+defines the passed control sequence as an integer, which then has to be used
+to define the actual Lua command with \cs{luadef}. After that, the integer is
+no longer needed. This was inconsistent with other allocators. Therefore we
+added two new allocators \cs{newluacmd} and \cs{newexpandableluacmd} which
+directly define a control sequences invoking the allocated Lua function.
+The first one defines a non-expandable Lua command, the second one an expandable
+one. Of course, the associated Lua function still has to be defined by assigning
+a function to the \verb|lua.get_functions_table()| table. The required index is
+available in \cs{allocationnumber}.
+
+An example could be
+\begin{verbatim}
+\newluacmd \greeting
+\directlua {
+lua.get_functions_table()
+   [tex.count.allocationnumber]
+   = function()
+    local name = token.scan_argument()
+    tex.sprint('Hello ', name, '!')
+  end
+}
+
+\greeting{world}
+\end{verbatim}
+%
+\githubissue{536}
+
+
+
 \subsection{???}
 %
 \githubissue{???}





More information about the latex3-commits mailing list.