[latex3-commits] [git/LaTeX3-latex3-latex3] main: Uncomplicate things (7d3f06d7b)
Max Chernoff
49086429+gucci-on-fleek at users.noreply.github.com.org
Sun May 15 23:18:08 CEST 2022
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/7d3f06d7bd4b1414d6be2624dc925ba52d370aa5
>---------------------------------------------------------------
commit 7d3f06d7bd4b1414d6be2624dc925ba52d370aa5
Author: Max Chernoff <49086429+gucci-on-fleek at users.noreply.github.com>
Date: Sun May 15 15:18:08 2022 -0600
Uncomplicate things
>---------------------------------------------------------------
7d3f06d7bd4b1414d6be2624dc925ba52d370aa5
l3kernel/l3luatex.dtx | 61 ++++++++++-----------------------------------------
1 file changed, 11 insertions(+), 50 deletions(-)
diff --git a/l3kernel/l3luatex.dtx b/l3kernel/l3luatex.dtx
index 1d1eb218c..e80df02bf 100644
--- a/l3kernel/l3luatex.dtx
+++ b/l3kernel/l3luatex.dtx
@@ -187,14 +187,6 @@
% found, nothing is returned with \emph{no error raised}.
% \end{function}
%
-% \begin{function}[added = 2022-05-14]{ltx.utils.require}
-% \begin{syntax}
-% |err_msg = ltx.utils.require(|\meta{module name}|)| \\
-% \end{syntax}
-% Loads a Lua module, returining |nil| on success and an error message
-% on failure.
-% \end{function}
-%
% \end{documentation}
%
% \begin{implementation}
@@ -249,16 +241,16 @@
% \end{macro}
%
% \begin{macro}{\lua_load_module:n}
-% Wrapper around |ltx.utils.require'|\meta{module}|'|.
+% Wrapper around |require'|\meta{module}|'|.
% \begin{macrocode}
-\cs_generate_variant:Nn \bool_if:nF { e }
+\str_new:N \l_@@_err_msg_str
\cs_generate_variant:Nn \msg_error:nnnn { nnnV }
\cs_new_protected:Npn \lua_load_module:n #1
{
- \bool_if:eF { \@@_load_module_p:n { #1 } }
+ \bool_if:nF { \@@_load_module_p:n { #1 } }
{
\msg_error:nnnV
- { luatex } { module-not-found } { #1 } { \g_@@_err_msg_str }
+ { luatex } { module-not-found } { #1 } { \l_@@_err_msg_str }
}
}
% \end{macrocode}
@@ -616,42 +608,11 @@ end
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{ltx.utils.require}
-% Loads a Lua module. This function loads the module just like the standard
-% Lua global function |require|, with two key differences:
-% \begin{enumerate}
-% \item This function is guaranteed not to throw an error.
-% \item This function does \emph{not} return the loaded module; instead, it
-% returns |nil| on success and an error message on failure.
-% \end{enumerate}
-% \begin{macrocode}
-local function require(name)
- if package_loaded[name] then
- return
- end
-
- local failure_details = {}
- for _, searcher in ipairs(package_searchers) do
- local loader, data = searcher(name)
- if type(loader) == 'function' then
- package_loaded[name] = loader(name, data) or true
- return
- elseif type(loader) == 'string' then
- failure_details[#failure_details + 1] = loader
- end
- end
-
- return table_concat(failure_details, '\n')
-end
-
-ltx.utils.require = require
-% \end{macrocode}
-% \end{macro}
%
% \begin{macro}{\@@_load_module_p:n}
-% Check to see if we can load a module using |ltx.utils.require|. If we can
-% load the module, then we load it immediately. Otherwise, we save the error
-% message in |\g_@@_err_msg_str|.
+% Check to see if we can load a module using |require|. If we
+% can load the module, then we load it immediately. Otherwise, we save the
+% error message in |\l_@@_err_msg_str|.
% \begin{macrocode}
local char_given = command_id'char_given'
local c_true_bool = token_create(1, char_given)
@@ -659,12 +620,12 @@ local c_false_bool = token_create(0, char_given)
local c_str_cctab = token_create('c_str_cctab').mode
luacmd('@@_load_module_p:n', function()
- local result = require(scan_string())
- if result == nil then
- set_macro(c_str_cctab, 'g_@@_err_msg_str', '', 'global')
+ local success, result = pcall(require, scan_string())
+ if success then
+ set_macro(c_str_cctab, 'l_@@_err_msg_str', '')
put_next(c_true_bool)
else
- set_macro(c_str_cctab, 'g_@@_err_msg_str', result, 'global')
+ set_macro(c_str_cctab, 'l_@@_err_msg_str', result)
put_next(c_false_bool)
end
end)
More information about the latex3-commits
mailing list.