[latex3-commits] [git/LaTeX3-latex3-latex3] luaintarray: Replace ad-hoc constructions with token_create_safe method (a24ecbda8)
Marcel Fabian Krüger
tex at 2krueger.de
Sat Nov 13 21:40:40 CET 2021
Repository : https://github.com/latex3/latex3
On branch : luaintarray
Link : https://github.com/latex3/latex3/commit/a24ecbda8aacf715a1ba62dd254f73059b3b79af
>---------------------------------------------------------------
commit a24ecbda8aacf715a1ba62dd254f73059b3b79af
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sat Nov 13 21:40:40 2021 +0100
Replace ad-hoc constructions with token_create_safe method
>---------------------------------------------------------------
a24ecbda8aacf715a1ba62dd254f73059b3b79af
l3kernel/l3bootstrap.dtx | 7 -------
l3kernel/l3intarray.dtx | 17 +++++------------
l3kernel/l3luatex.dtx | 30 ++++++++++++++++++++++++++++--
3 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/l3kernel/l3bootstrap.dtx b/l3kernel/l3bootstrap.dtx
index 3f715c817..f0fafc290 100644
--- a/l3kernel/l3bootstrap.dtx
+++ b/l3kernel/l3bootstrap.dtx
@@ -189,18 +189,11 @@
% \end{macrocode}
% For \LuaTeX{} we make sure the basic support is loaded:
% this is only necessary in plain.
-%
-% Additionally we just ensure that \TeX{} has seen the csnames \cs{prg_return_true:}
-% and \cs{prg_return_false:} before the Lua code builds these tokens.
% \begin{macrocode}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname newcatcodetable\endcsname\relax
\input{ltluatex}%
\fi
- \begingroup\edef\ignored{%
- \expandafter\noexpand\csname prg_return_true:\endcsname
- \expandafter\noexpand\csname prg_return_false:\endcsname
- }\endgroup
\ifdefined\newluabytecode\newluabytecode\@expl at luadata@bytecode\fi
\directlua{require("expl3")}%
% \end{macrocode}
diff --git a/l3kernel/l3intarray.dtx b/l3kernel/l3intarray.dtx
index ce96861ee..b824a4898 100644
--- a/l3kernel/l3intarray.dtx
+++ b/l3kernel/l3intarray.dtx
@@ -265,20 +265,13 @@ end, 'protected', 'global')
% \begin{macrocode}
%<*lua>
-tex.runtoks(function()
- tex.sprint("\\begingroup\\catcode`\\:=11 \\catcode`\\_=11\z
- \\def\\__luatex_dummy:{\z
- \\@@:w\\use:n\\use_none:n\\exp_after:wN\\scan_stop:\z
- }\\endgroup")
-end)
-
local scan_token = token.scan_token
local put_next = token.put_next
-local intarray_marker = token_create'@@:w'
-local use_none = token_create'use_none:n'
-local use_i = token_create'use:n'
-local expand_after_scan_stop = {token_create'exp_after:wN',
- token_create'scan_stop:'}
+local intarray_marker = token_create_safe'@@:w'
+local use_none = token_create_safe'use_none:n'
+local use_i = token_create_safe'use:n'
+local expand_after_scan_stop = {token_create_safe'exp_after:wN',
+ token_create_safe'scan_stop:'}
local comma = token_create(string.byte',')
% \end{macrocode}
%
diff --git a/l3kernel/l3luatex.dtx b/l3kernel/l3luatex.dtx
index 0c945dd0c..60e87235c 100644
--- a/l3kernel/l3luatex.dtx
+++ b/l3kernel/l3luatex.dtx
@@ -371,9 +371,35 @@ local scan_string = token.scan_string
local scan_keyword = token.scan_keyword
local put_next = token.put_next
local token_create = token.create
+% \end{macrocode}
+%
+% Since token.create only returns useful values after the tokens
+% has been added to TeX's hash table, we define a variant which
+% defines it first if necessary.
+% \begin{macrocode}
+local token_create_safe
+do
+ local is_defined = token.is_defined
+ local set_char = token.set_char
+ local runtoks = tex.runtoks
+ local let_token = token_create'let'
+
+ function token_create_safe(s)
+ local orig_token = token_create(s)
+ if is_defined(s, true) then
+ return orig_token
+ end
+ set_char(s, 0)
+ local new_token = token_create(s)
+ runtoks(function()
+ put_next(let_token, new_token, orig_token)
+ end)
+ return new_token
+ end
+end
-local true_tok = token_create'prg_return_true:'
-local false_tok = token_create'prg_return_false:'
+local true_tok = token_create_safe'prg_return_true:'
+local false_tok = token_create_safe'prg_return_false:'
% \end{macrocode}
%
% \begin{macrocode}
More information about the latex3-commits
mailing list.