[latex3-commits] [git/LaTeX3-latex3-latex3] luaintarray: Make csnames known explicitly before running token.create (5a2fa14f2)

Marcel Fabian Krüger tex at 2krueger.de
Sat Nov 13 14:38:21 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : luaintarray
Link       : https://github.com/latex3/latex3/commit/5a2fa14f2fe9805735078b8420a7ebf17858f6b8

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

commit 5a2fa14f2fe9805735078b8420a7ebf17858f6b8
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Sat Nov 13 14:34:56 2021 +0100

    Make csnames known explicitly before running token.create


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

5a2fa14f2fe9805735078b8420a7ebf17858f6b8
 l3kernel/l3intarray.dtx | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/l3kernel/l3intarray.dtx b/l3kernel/l3intarray.dtx
index 83d7be8bd..813f0f194 100644
--- a/l3kernel/l3intarray.dtx
+++ b/l3kernel/l3intarray.dtx
@@ -258,30 +258,38 @@ end, 'protected', 'global')
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{@@_table}
-%   Internal helper to scan an intarray token, extract the associated
-%   Lua table and return an error if the input is invalid.
+% Before we get to the first command implmented in Lua, we first need some
+% definitions. Since \texttt{token.create} only works correctly if \TeX{}
+% has seen the tokens before, we first run a short \TeX{} sequence to ensure
+% that all relevant control sequences are known.
 %    \begin{macrocode}
 %<*lua>
 
+tex.runtoks(function()
+  tex.sprint("\\begingroup\\catcode`\\:=11 \\catcode`\\_=11\z
+    \\def\\__luatex_dummy:{\z
+      \\s_@@\\use:n\\use_none:n\\exp_after:wN\\scan_stop:\z
+    }\\endgroup")
+end)
+
 local scan_token = token.scan_token
 local scan_toks = token.scan_toks
 local get_csname = token.get_csname
 local put_next = token.put_next
 local s_@@ = token_create's_@@'
-local use_none
-local expand_after_scan_stop
-local comma = token_create(string.byte',')
-
+local use_none = token_create'use_none:n'
 local use_i = token_create'use:n'
-if use_i.cmdname == "undefined_cs" then
-  use_i = nil
-else
-  use_none = token_create'use_none:n'
-  expand_after_scan_stop = {token_create'exp_after:wN', token_create'scan_stop:'}
-end
-
+local expand_after_scan_stop = {token_create'exp_after:wN',
+                                token_create'scan_stop:'}
+local comma = token_create(string.byte',')
 local scan_argument = token.scan_argument
+%    \end{macrocode}
+%
+% \begin{macro}{@@_table}
+%   Internal helper to scan an intarray token, extract the associated
+%   Lua table and return an error if the input is invalid.
+%
+%    \begin{macrocode}
 local @@_table do
   local tables = get_luadata and get_luadata'@@' or {[0] = {}}
   function @@_table()
@@ -320,11 +328,6 @@ end
 local sprint = tex.sprint
 
 luacmd('@@_gset_count:Nw', function()
-  if not use_i then
-    use_i = token_create'use:n'
-    use_none = token_create'use_none:n'
-    expand_after_scan_stop = {token_create'exp_after:wN', token_create'scan_stop:'}
-  end
   local t = @@_table()
   local n = scan_int()
   for i=#t+1, n do t[i] = 0 end





More information about the latex3-commits mailing list.