From 1890f892975db4b08c649e9c14d26f28b122ed57 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 27 Jun 2022 20:18:50 +0000 Subject: lt3luabridge (27jun22) git-svn-id: svn://tug.org/texlive/trunk@63735 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/doc/generic/lt3luabridge/README.md | 2 +- .../doc/generic/lt3luabridge/docstrip.cfg | 5 +- .../doc/generic/lt3luabridge/lt3luabridge.pdf | Bin 0 -> 503613 bytes .../source/generic/lt3luabridge/lt3luabridge.dtx | 681 +++++++++++++++++++++ .../source/generic/lt3luabridge/lt3luabridge.ins | 7 + .../tex/generic/lt3luabridge/lt3luabridge.sty | 51 +- .../tex/generic/lt3luabridge/lt3luabridge.tex | 244 +++++--- .../tex/generic/lt3luabridge/t-lt3luabridge.tex | 47 ++ 8 files changed, 952 insertions(+), 85 deletions(-) create mode 100644 Master/texmf-dist/doc/generic/lt3luabridge/lt3luabridge.pdf create mode 100644 Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.dtx create mode 100644 Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.ins diff --git a/Master/texmf-dist/doc/generic/lt3luabridge/README.md b/Master/texmf-dist/doc/generic/lt3luabridge/README.md index 5c4a3f50c31..a9257f4e09d 100644 --- a/Master/texmf-dist/doc/generic/lt3luabridge/README.md +++ b/Master/texmf-dist/doc/generic/lt3luabridge/README.md @@ -9,7 +9,7 @@ the shell: ``` tex \documentclass{standalone} -\usepackage{l3luabridge} +\usepackage{lt3luabridge} \begin{document} $ 1 + 2 = \luabridgeExecute{ print(1 + 2) } $ \end{document} diff --git a/Master/texmf-dist/doc/generic/lt3luabridge/docstrip.cfg b/Master/texmf-dist/doc/generic/lt3luabridge/docstrip.cfg index 06c65a3c2a9..4e131f18492 100644 --- a/Master/texmf-dist/doc/generic/lt3luabridge/docstrip.cfg +++ b/Master/texmf-dist/doc/generic/lt3luabridge/docstrip.cfg @@ -3,15 +3,12 @@ Copyright (C) 2016-2022 Vít Novotný This work may be distributed and/or modified under the -conditions of the LaTeX Project Public License, either version 1.3 +conditions of the LaTeX Project Public License, either version 1.3c of this license or (at your option) any later version. The latest version of this license is in http://www.latex-project.org/lppl.txt -and version 1.3 or later is part of all distributions of LaTeX -version 2005/12/01 or later. - This work has the LPPL maintenance status `maintained'. The Current Maintainer of this work is Vít Novotný. diff --git a/Master/texmf-dist/doc/generic/lt3luabridge/lt3luabridge.pdf b/Master/texmf-dist/doc/generic/lt3luabridge/lt3luabridge.pdf new file mode 100644 index 00000000000..de17e2ed211 Binary files /dev/null and b/Master/texmf-dist/doc/generic/lt3luabridge/lt3luabridge.pdf differ diff --git a/Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.dtx b/Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.dtx new file mode 100644 index 00000000000..71db99dce55 --- /dev/null +++ b/Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.dtx @@ -0,0 +1,681 @@ +% \iffalse +%<*driver> +\documentclass[full]{l3doc} +\usepackage{hologo} +\begin{filecontents}[overwrite,nosearch,noheader]{\jobname.bib} + +@online{expl3, + title = {expl3}, + subtitle = {Wrapper package for experimental \LaTeX3}, + author = {{The \LaTeX{} Team}}, + publisher = {{CTAN}}, + date = {2022-06-16}, + urldate = {2022-06-26}, + url = {https://ctan.org/pkg/expl3}, +} + +@online{markdown, + title = {Markdown}, + subtitle = {A package for converting and rendering markdown documents inside \TeX}, + author = {Vít Novotný}, + publisher = {{CTAN}}, + date = {2022-05-31}, + urldate = {2022-06-26}, + url = {https://ctan.org/pkg/markdown}, + note = {Version 2.15.2-0-gb238dbc}, +} + +\end{filecontents} +\usepackage{biblatex} +\addbibresource{\jobname.bib} +\begin{document} + \DocInput{\jobname.dtx} +\end{document} +% +% \fi +% +% \title{^^A +% The \textsf{lt3luabridge} package: \Lua{} without \Lua\TeX^^A +% } +% +% \author{^^A +% Vít Novotný\thanks +% {^^A +% E-mail: +% \href{mailto:witiko@mail.muni.cz} +% {witiko@mail.muni.cz}^^A +% }^^A +% } +% +% \date{Released 2022-06-26} +% +% \maketitle +% +% \begin{documentation} +% +% The \pkg{lt3luabridge} expl3~\cite{expl3} package provides support for +% executing \Lua{} code in \Lua\TeX{} or any other \TeX{} engine that exposes +% the shell. The package provides interfaces to plain \TeX, \LaTeX, and +% \Hologo{ConTeXt} +% formats: +% \begin{verbatim} +% \documentclass{standalone} +% \usepackage{lt3luabridge} +% \begin{document} +% $ 1 + 2 = \luabridgeExecute{ print(1 + 2) } $ +% \end{document} +% \end{verbatim} +% The package was previously part of the Markdown package~\cite{markdown}, +% where it has been battle-tested since 2016. Since 2022, lt3luabridge has +% also been available as a separate package. +% +% \section{Loading the package} +% +% Use the |\input lt3luabridge\relax| command to load the package from plain \TeX, +% use the |\usepackage{lt3luabridge}| command to load the package from \LaTeX, and +% use the |\usemodule[t][lt3luabridge]| command to load the package from \Hologo{ConTeXt}. +% +% \section{Executing \Lua{} code} +% +% The interface for executing \Lua{} code mimics the \cs{lua_now:n} function +% from \pkg{l3luatex}. +% +% \begin{function}[added = 2022-06-26]{\luabridge_now:n, \luabridge_now:e} +% \begin{syntax} +% \cs{luabridge_now:n} \Arg{token list} +% \end{syntax} +% The \meta{token list} is first tokenized by \TeX{}, which includes +% converting line ends to spaces in the usual \TeX{} manner and which +% respects currently-applicable \TeX{} category codes. The resulting +% \meta{\Lua{} input} is passed to the \Lua{} interpreter for processing. +% Each \cs{luabridge_now:n} block is treated by \Lua{} as a separate chunk. +% The \Lua{} interpreter executes the \meta{\Lua{} input} immediately, +% and in an expandable manner. +% +% Unlike \cs{lua_now:n}, \cs{luabridge_now:n} may execute \meta{\Lua{} input} +% in a separate process from \TeX. Therefore, you should not interact with +% \TeX{} from \meta{\Lua{} input}. The only exception is the standard output +% produced by \meta{\Lua{} input} using for example the |print()| \Lua{} +% function like in the example at the top of this page. The standard output +% will be inserted into \TeX's input stream after \meta{\Lua{} input} has +% been processed at the latest. +% \end{function} +% +% \begin{function}[added = 2022-06-26]{\luabridgeExecute} +% \begin{syntax} +% \cs{luabridgeExecute} \Arg{token list} +% \end{syntax} +% The \cs{luabridgeExecute} document command aliases +% the \cs{luabridge_now:e} function. +% \end{function} +% +% \section{Setting and getting the method to execute \Lua{} code} +% +% There are several methods that can be used to execute \Lua{} code. This +% section describes the interface that the package provides to set the +% preferred method or to determine which method was used. +% +% \begin{variable}[added = 2022-06-26]{\g_luabridge_method_int} +% This variable controls the method used to execute \Lua{} code. +% The variable is set automatically when the package is loaded +% and changing the value of the variable afterwards has no effect. +% However, we can set the value of the variable before loading the +% package to one of the constants described below. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_method_write_eighteen_int} +% Use shell escape through the \cs{write18} \TeX{} command to execute \Lua{} code. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_method_os_execute_int} +% Use shell escape through the |os.execute()| Lua function to execute \Lua{} code. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_method_directlua_int} +% Use the \cs{directlua} primitive of Lua\TeX{} to execute \Lua{} code. +% \end{variable} +% +% \section{Setting and getting the filenames of helper files} +% +% When shell escape is used to execute \Lua{} code, several helper files are +% needed to shuffle around code and output. The following variables and +% constants are undefined when the \cs{directlua} primitive of Lua\TeX{} is +% used to execute \Lua{} code. +% +% \begin{variable}[added = 2022-06-26]{\g_luabridge_output_dirname_str} +% This variable controls the output directory that will store the helper +% files. The variable should be set to the same value as the +% \texttt{-output-directory} parameter of the \TeX{} engine. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_default_output_dirname_str} +% This constant is the default value of \cs{g_luabridge_output_dirname_str}. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\g_luabridge_helper_script_filename_str} +% This variable controls the filename of a helper \Lua{} script that will be +% executed from the shell using the \TeX{} \Lua{} interpreter. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_default_helper_script_filename_str} +% This constant is the default value of +% \cs{g_luabridge_helper_script_filename_str}. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\g_luabridge_standard_output_filename_str} +% This variable controls the filename of a helper file that will contain the +% standard output produced by the |texlua| interpreter (if any). +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_default_standard_output_filename_str} +% This constant is the default value of +% \cs{g_luabridge_standard_output_filename_str}. +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\g_luabridge_error_output_filename_str} +% This variable controls the filename of a helper file that will contain the +% error output produced by the |texlua| interpreter (if any). +% \end{variable} +% +% \begin{variable}[added = 2022-06-26]{\c_luabridge_default_error_output_filename_str} +% This constant is the default value of +% \cs{g_luabridge_error_output_filename_str}. +% \end{variable} +% +% \end{documentation} +% +% \begin{implementation} +% +% \section{Plain \TeX{} implementation} +% +% This section contains the implementation for plain \TeX{} using generic expl3. +% +% \begin{macrocode} +%<@@=luabridge> +%<*generic-package> +\ifx\ExplSyntaxOn\undefined + \input expl3-generic\relax +\fi +\ExplSyntaxOn +\int_const:Nn + \c_luabridge_method_write_eighteen_int + { 0 } +\int_const:Nn + \c_luabridge_method_os_execute_int + { 1 } +\int_const:Nn + \c_luabridge_method_directlua_int + { 2 } +\int_if_exist:NF + \g_luabridge_method_int + { + \int_new:N + \g_luabridge_method_int + \sys_if_engine_luatex:TF + { + \int_gset_eq:NN + \g_luabridge_method_int + \c_luabridge_method_directlua_int + } + { + \int_gset_eq:NN + \g_luabridge_method_int + \c_luabridge_method_write_eighteen_int + } + } +\msg_new:nnn + { luabridge } + { unknown-method } + { + Unknown~bridging~method:~#1 + } +\msg_new:nnn + { luabridge } + { method-write-eighteen } + { + Using~shell~escape~via~write18~as~the~bridging~method + } +\msg_new:nnn + { luabridge } + { method-os-execute } + { + Using~shell~escape~via~os.execute()~as~the~bridging~method + } +\msg_new:nnn + { luabridge } + { method-directlua } + { + Using~direct~Lua~access~as~the~bridging~method + } +\int_case:nnF + { \g_luabridge_method_int } + { + { \c_luabridge_method_write_eighteen_int } + { + \msg_info:nn + { luabridge } + { method-write-eighteen } + } + { \c_luabridge_method_os_execute_int } + { + \msg_info:nn + { luabridge } + { method-os-execute } + } + { \c_luabridge_method_directlua_int } + { + \msg_info:nn + { luabridge } + { method-directlua } + } + } + { + \cs_generate_variant:Nn + \msg_error:nnn + { nnV } + \msg_error:nnV + { luabridge } + { unknown-method } + \g_luabridge_method_int + } +\bool_if:nTF + { + \int_compare_p:nNn + { \g_luabridge_method_int } + = + { \c_luabridge_method_write_eighteen_int } || + \int_compare_p:nNn + { \g_luabridge_method_int } + = + { \c_luabridge_method_os_execute_int } + } + { + \int_const:Nn + \c_@@_level_disabled_int + { 0 } + \int_const:Nn + \c_@@_level_enabled_int + { 1 } + \int_const:Nn + \c_@@_level_restricted_int + { 2 } + \int_new:N + \l_@@_level_int + \cs_if_exist:NTF + \pdfshellescape + { + \int_gset:Nn + \l_@@_level_int + { \pdfshellescape } + } + { + \cs_if_exist:NTF + \shellescape + { + \int_gset:Nn + \l_@@_level_int + { \shellescape } + } + { + \int_case:nnF + { \g_luabridge_method_int } + { + { \c_luabridge_method_write_eighteen_int } + { + \int_gset_eq:NN + \l_@@_level_int + \c_@@_level_enabled_int + } + } + { + \int_gset:Nn + \l_@@_level_int + { + \lua_now:n + { + tex.sprint(status.shell_escape or "1") + } + } + } + } + } + \msg_new:nnn + { luabridge } + { unknown-level } + { + Unknown~shell~escape~level:~#1 + } + \msg_new:nnnn + { luabridge } + { level-disabled } + { + Shell~escape~seems~to~be~disabled + } + { + You~may~need~to~run~TeX~with~the~--shell-escape~or~the~ + --enable-write18~flag,~or~write~shell_escape=t~in~the~ + texmf.cnf~file. + } + \msg_new:nnn + { luabridge } + { level-enabled } + { + Shell~escape~seems~to~be~enabled + } + \msg_new:nnnn + { luabridge } + { level-restricted } + { + Shell~escape~seems~to~be~restricted + } + { + You~may~need~to~run~TeX~with~the~--shell-escape~or~the~ + --enable-write18~flag,~or~write~shell_escape=t~in~the~ + texmf.cnf~file. + } + \str_const:Nn + \c_luabridge_default_output_dirname_str + { . } + \str_const:Nx + \c_luabridge_default_helper_script_filename_str + { \jobname.luabridge.lua } + \str_const:Nx + \c_luabridge_default_error_output_filename_str + { \jobname.luabridge.err } + \str_const:Nx + \c_luabridge_default_standard_output_filename_str + { \jobname.luabridge.out } + \int_case:nnF + { \l_@@_level_int } + { + { \c_@@_level_disabled_int } + { + \msg_warning:nn + { luabridge } + { level-disabled } + } + { \c_@@_level_enabled_int } + { + \msg_info:nn + { luabridge } + { level-enabled } + } + { \c_@@_level_restricted_int } + { + \msg_warning:nn + { luabridge } + { level-restricted } + } + } + { + \msg_error:nnx + { luabridge } + { unknown-level } + { \l_@@_level_int } + } + \cs_new:Nn + \_luabridge_assert_shell_escape: + { + \int_case:nnF + { \l_@@_level_int } + { + { \c_@@_level_disabled_int } + { + \msg_error:nn + { luabridge } + { level-disabled } + } + } + } + \int_case:nn + { \g_luabridge_method_int } + { + { \c_luabridge_method_write_eighteen_int } + { + \cs_new:Nn + \_luabridge_execute_shell:n + { + \_luabridge_assert_shell_escape: + \immediate + \write 18 + { #1 } + } + } + { \c_luabridge_method_os_execute_int } + { + \cs_new:Nn + \_luabridge_execute_shell:n + { + \_luabridge_assert_shell_escape: + \lua_now:e + { + os.execute( + " \lua_escape:e { #1 } " + ) + } + } + } + } + \str_if_exist:NF + \g_luabridge_output_dirname_str + { + \str_new:N + \g_luabridge_output_dirname_str + \tl_gset:Nn + \g_luabridge_output_dirname_str + \c_luabridge_default_output_dirname_str + } + \str_if_exist:NF + \g_luabridge_helper_script_filename_str + { + \str_gset_eq:NN + \g_luabridge_helper_script_filename_str + \c_luabridge_default_helper_script_filename_str + } + \str_if_exist:NF + \g_luabridge_error_output_filename_str + { + \str_gset_eq:NN + \g_luabridge_error_output_filename_str + \c_luabridge_default_error_output_filename_str + } + \str_if_exist:NF + \g_luabridge_standard_output_filename_str + { + \str_gset_eq:NN + \g_luabridge_standard_output_filename_str + \c_luabridge_default_standard_output_filename_str + } + \cs:w newwrite \cs_end: + \l_@@_output_stream + \cs_new:Nn + \luabridge_now:n + { + \immediate \openout + \l_@@_output_stream + \g_luabridge_helper_script_filename_str + \msg_info:nnV + { luabridge } + { writing-helper-script } + \g_luabridge_helper_script_filename_str + \tl_set:Nn + \l_tmpa_tl + { #1 } + \tl_set:Nx + \l_tmpb_tl + { + local~ran_ok,~error~=~pcall(function()~ + local~ran_ok,~kpse~=~pcall(require,~"kpse")~ + if~ran_ok~then~kpse.set_program_name("luatex")~end~ + \exp_not:V \l_tmpa_tl~ + end)~ + if~not~ran_ok~then~ + local~file~=~io.open(" + \g_luabridge_output_dirname_str / + \g_luabridge_error_output_filename_str + ",~"w")~ + if~file~then~ + file:write(error~..~" \iow_char:N \\ n ")~ + file:close()~ + end~ + print(' + \iow_char:N \\ \iow_char:N \\ begingroup + \iow_char:N \\ \iow_char:N \\ ExplSyntaxOn + \iow_char:N \\ \iow_char:N \\ msg_error:nnvv + { luabridge } + { failed-to-execute } + { g_luabridge_output_dirname_str } + { g_luabridge_output_dirname_str } + \iow_char:N \\ \iow_char:N \\ endgroup + ')~ + end + } + \immediate \write + \l_@@_output_stream + { \exp_not:V \l_tmpb_tl } + \immediate \closeout + \l_@@_output_stream + \msg_info:nnVV + { luabridge } + { executing-helper-script } + \g_luabridge_helper_script_filename_str + \g_luabridge_standard_output_filename_str + \tl_set:Nx + \l_tmpa_tl + { + texlua~" + \g_luabridge_output_dirname_str / + \g_luabridge_helper_script_filename_str + "~>~" + \g_luabridge_output_dirname_str / + \g_luabridge_standard_output_filename_str + " + } + \_luabridge_execute_shell:V + \l_tmpa_tl + \file_if_exist_input:VF + \g_luabridge_standard_output_filename_str + { + \msg_error:nn + { luabridge } + { level-disabled } + } + } + \cs_generate_variant:Nn + \msg_info:nnn + { nnV } + \cs_generate_variant:Nn + \msg_info:nnnn + { nnVV } + \cs_generate_variant:Nn + \msg_error:nnnn + { nnvv } + \cs_generate_variant:Nn + \_luabridge_execute_shell:n + { V } + \prg_generate_conditional_variant:Nnn + \file_if_exist_input:n + { V } + { F } + \msg_new:nnn + { luabridge } + { writing-helper-script } + { + Writing~a~helper~Lua~script~to~file~#1 + } + \msg_new:nnn + { luabridge } + { executing-helper-script } + { + Executing~a~helper~Lua~script~from~file~#1~ + and~storing~the~result~in~file~#2 + } + \msg_new:nnnn + { luabridge } + { failed-to-execute } + { + An~error~was~encountered~while~executing~Lua~code + } + { + For further clues, examine file #1/#2 + } + } + { + \cs_new:Nn + \luabridge_now:n + { + \tl_set:Nn + \l_tmpa_tl + { #1 } + \tl_set:Nx + \l_tmpb_tl + { + local~function~print(input)~ + input~=~tostring(input)~ + local~output~=~{}~ + for~line~in~input:gmatch("[^ + \iow_char:N \\ r + \iow_char:N \\ n + ]+")~do~ + table.insert(output,~line)~ + end~ + tex.print(output)~ + end~ + \exp_not:V \l_tmpa_tl + } + \lua_now:V + \l_tmpb_tl + } + \cs_generate_variant:Nn + \lua_now:n + { V } + } +\cs_new_protected:Npn + \luabridgeExecute + #1 + { + \luabridge_now:e + { #1 } + } +\cs_generate_variant:Nn + \luabridge_now:n + { e } +\ExplSyntaxOff +% +% \end{macrocode} +% +% \section{\LaTeX{} implementation} +% +% This section contains the implementation for \LaTeX. +% +% \begin{macrocode} +%<*latex-package> +\RequirePackage{expl3} +\ProvidesExplPackage + {lt3luabridge}% + {2022-06-26}% + {1.0.1}% + {An expl3 package that allows you to execute Lua code in LuaTeX or any other + TeX engine that exposes the shell} +\input lt3luabridge\relax +% +% \end{macrocode} +% +% \section{\Hologo{ConTeXt} implementation} +% +% This section contains the implementation for \Hologo{ConTeXt}. +% \Hologo{ConTeXt} MkII, MkIV, and later formats are supported. +% +% \begin{macrocode} +%<*context-package> +\writestatus{loading}{ConTeXt User Module / lt3luabridge} +\startmodule[lt3luabridge] +\unprotect +\input lt3luabridge\relax +% +% \end{macrocode} +% +% \end{implementation} +% +% \printbibliography +% \PrintIndex diff --git a/Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.ins b/Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.ins new file mode 100644 index 00000000000..35c23c4a395 --- /dev/null +++ b/Master/texmf-dist/source/generic/lt3luabridge/lt3luabridge.ins @@ -0,0 +1,7 @@ +\input l3docstrip.tex +\generate{ + \file{lt3luabridge.tex}{\from{lt3luabridge.dtx}{generic-package}} + \file{lt3luabridge.sty}{\from{lt3luabridge.dtx}{latex-package}} + \file{t-lt3luabridge.tex}{\from{lt3luabridge.dtx}{context-package}} +} +\endbatchfile diff --git a/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.sty b/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.sty index fc786140c6f..c4f14db05e9 100644 --- a/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.sty +++ b/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.sty @@ -1,8 +1,55 @@ +%% +%% This is file `lt3luabridge.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% lt3luabridge.dtx (with options: `latex-package') +%% +%% Copyright (C) 2016-2022 Vít Novotný +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This work has the LPPL maintenance status `maintained'. +%% The Current Maintainer of this work is Vít Novotný. +%% +%% Send bug reports, requests for additions and questions +%% either to the GitHub issue tracker at +%% +%% https://github.com/Witiko/lt3luabridge/issues +%% +%% or to the e-mail address . +%% +%% MODIFICATION ADVICE: +%% +%% If you want to customize this file, it is best to make a copy of +%% the source file(s) from which it was produced. Use a different +%% name for your copy(ies) and modify the copy(ies); this will ensure +%% that your modifications do not get overwritten when you install a +%% new release of the standard system. You should also ensure that +%% your modified source file does not generate any modified file with +%% the same name as a standard file. +%% +%% You will also need to produce your own, suitably named, .ins file to +%% control the generation of files from your source file; this file +%% should contain your own preambles for the files it generates, not +%% those in the standard .ins files. +%% +%% The names of the source files used are shown above. +%% \RequirePackage{expl3} \ProvidesExplPackage {lt3luabridge}% - {2022-06-25}% - {1.0.0}% + {2022-06-26}% + {1.0.1}% {An expl3 package that allows you to execute Lua code in LuaTeX or any other TeX engine that exposes the shell} \input lt3luabridge\relax +\endinput +%% +%% End of file `lt3luabridge.sty'. diff --git a/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.tex b/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.tex index 0c2b8f8ddd6..bdaf2c38a9d 100644 --- a/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.tex +++ b/Master/texmf-dist/tex/generic/lt3luabridge/lt3luabridge.tex @@ -1,26 +1,75 @@ +%% +%% This is file `lt3luabridge.tex', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% lt3luabridge.dtx (with options: `generic-package') +%% +%% Copyright (C) 2016-2022 Vít Novotný +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This work has the LPPL maintenance status `maintained'. +%% The Current Maintainer of this work is Vít Novotný. +%% +%% Send bug reports, requests for additions and questions +%% either to the GitHub issue tracker at +%% +%% https://github.com/Witiko/lt3luabridge/issues +%% +%% or to the e-mail address . +%% +%% MODIFICATION ADVICE: +%% +%% If you want to customize this file, it is best to make a copy of +%% the source file(s) from which it was produced. Use a different +%% name for your copy(ies) and modify the copy(ies); this will ensure +%% that your modifications do not get overwritten when you install a +%% new release of the standard system. You should also ensure that +%% your modified source file does not generate any modified file with +%% the same name as a standard file. +%% +%% You will also need to produce your own, suitably named, .ins file to +%% control the generation of files from your source file; this file +%% should contain your own preambles for the files it generates, not +%% those in the standard .ins files. +%% +%% The names of the source files used are shown above. +%% \ifx\ExplSyntaxOn\undefined \input expl3-generic\relax \fi \ExplSyntaxOn -\int_const:Nn \c__luabridge_method_write_eighteen_int { 0 } -\int_const:Nn \c__luabridge_method_os_execute_int { 1 } -\int_const:Nn \c__luabridge_method_directlua_int { 2 } +\int_const:Nn + \c_luabridge_method_write_eighteen_int + { 0 } +\int_const:Nn + \c_luabridge_method_os_execute_int + { 1 } +\int_const:Nn + \c_luabridge_method_directlua_int + { 2 } \int_if_exist:NF - \g__luabridge_method_int + \g_luabridge_method_int { \int_new:N - \g__luabridge_method_int - \cs_if_exist:NTF - \directlua + \g_luabridge_method_int + \sys_if_engine_luatex:TF { \int_gset_eq:NN - \g__luabridge_method_int - \c__luabridge_method_directlua_int + \g_luabridge_method_int + \c_luabridge_method_directlua_int } { \int_gset_eq:NN - \g__luabridge_method_int - \c__luabridge_method_write_eighteen_int + \g_luabridge_method_int + \c_luabridge_method_write_eighteen_int } } \msg_new:nnn @@ -48,21 +97,21 @@ Using~direct~Lua~access~as~the~bridging~method } \int_case:nnF - { \g__luabridge_method_int } + { \g_luabridge_method_int } { - { \c__luabridge_method_write_eighteen_int } + { \c_luabridge_method_write_eighteen_int } { \msg_info:nn { luabridge } { method-write-eighteen } } - { \c__luabridge_method_os_execute_int } + { \c_luabridge_method_os_execute_int } { \msg_info:nn { luabridge } { method-os-execute } } - { \c__luabridge_method_directlua_int } + { \c_luabridge_method_directlua_int } { \msg_info:nn { luabridge } @@ -70,33 +119,42 @@ } } { - \msg_error:nnx + \cs_generate_variant:Nn + \msg_error:nnn + { nnV } + \msg_error:nnV { luabridge } { unknown-method } - { \g__luabridge_method_int } + \g_luabridge_method_int } \bool_if:nTF { \int_compare_p:nNn - { \g__luabridge_method_int } + { \g_luabridge_method_int } = - { \c__luabridge_method_write_eighteen_int } || + { \c_luabridge_method_write_eighteen_int } || \int_compare_p:nNn - { \g__luabridge_method_int } + { \g_luabridge_method_int } = - { \c__luabridge_method_os_execute_int } + { \c_luabridge_method_os_execute_int } } { - \int_const:Nn \c__luabridge_level_disabled_int { 0 } - \int_const:Nn \c__luabridge_level_enabled_int { 1 } - \int_const:Nn \c__luabridge_level_restricted_int { 2 } + \int_const:Nn + \c__luabridge_level_disabled_int + { 0 } + \int_const:Nn + \c__luabridge_level_enabled_int + { 1 } + \int_const:Nn + \c__luabridge_level_restricted_int + { 2 } \int_new:N - \g__luabridge_level_int + \l__luabridge_level_int \cs_if_exist:NTF \pdfshellescape { \int_gset:Nn - \g__luabridge_level_int + \l__luabridge_level_int { \pdfshellescape } } { @@ -104,25 +162,25 @@ \shellescape { \int_gset:Nn - \g__luabridge_level_int + \l__luabridge_level_int { \shellescape } } { \int_case:nnF - { \g__luabridge_method_int } + { \g_luabridge_method_int } { - { \c__luabridge_method_write_eighteen_int } + { \c_luabridge_method_write_eighteen_int } { \int_gset_eq:NN - \g__luabridge_level_int + \l__luabridge_level_int \c__luabridge_level_enabled_int } } { \int_gset:Nn - \g__luabridge_level_int + \l__luabridge_level_int { - \directlua + \lua_now:n { tex.sprint(status.shell_escape or "1") } @@ -164,12 +222,20 @@ --enable-write18~flag,~or~write~shell_escape=t~in~the~ texmf.cnf~file. } - \str_const:Nn \c__luabridge_default_output_dirname_str { . } - \str_const:Nx \c__luabridge_default_helper_script_filename_str { \jobname.luabridge.lua } - \str_const:Nx \c__luabridge_default_error_output_filename_str { \jobname.luabridge.err } - \str_const:Nx \c__luabridge_default_standard_output_filename_str { \jobname.luabridge.out } + \str_const:Nn + \c_luabridge_default_output_dirname_str + { . } + \str_const:Nx + \c_luabridge_default_helper_script_filename_str + { \jobname.luabridge.lua } + \str_const:Nx + \c_luabridge_default_error_output_filename_str + { \jobname.luabridge.err } + \str_const:Nx + \c_luabridge_default_standard_output_filename_str + { \jobname.luabridge.out } \int_case:nnF - { \g__luabridge_level_int } + { \l__luabridge_level_int } { { \c__luabridge_level_disabled_int } { @@ -194,13 +260,13 @@ \msg_error:nnx { luabridge } { unknown-level } - { \g__luabridge_level_int } + { \l__luabridge_level_int } } \cs_new:Nn \_luabridge_assert_shell_escape: { \int_case:nnF - { \g__luabridge_level_int } + { \l__luabridge_level_int } { { \c__luabridge_level_disabled_int } { @@ -211,9 +277,9 @@ } } \int_case:nn - { \g__luabridge_method_int } + { \g_luabridge_method_int } { - { \c__luabridge_method_write_eighteen_int } + { \c_luabridge_method_write_eighteen_int } { \cs_new:Nn \_luabridge_execute_shell:n @@ -224,75 +290,78 @@ { #1 } } } - { \c__luabridge_method_os_execute_int } + { \c_luabridge_method_os_execute_int } { \cs_new:Nn \_luabridge_execute_shell:n { \_luabridge_assert_shell_escape: - \directlua + \lua_now:e { os.execute( - " \luaescapestring { #1 } " + " \lua_escape:e { #1 } " ) } } } } \str_if_exist:NF - \g__luabridge_output_dirname_str + \g_luabridge_output_dirname_str { \str_new:N - \g__luabridge_output_dirname_str + \g_luabridge_output_dirname_str \tl_gset:Nn - \g__luabridge_output_dirname_str - \c__luabridge_default_output_dirname_str + \g_luabridge_output_dirname_str + \c_luabridge_default_output_dirname_str } \str_if_exist:NF - \g__luabridge_helper_script_filename_str + \g_luabridge_helper_script_filename_str { \str_gset_eq:NN - \g__luabridge_helper_script_filename_str - \c__luabridge_default_helper_script_filename_str + \g_luabridge_helper_script_filename_str + \c_luabridge_default_helper_script_filename_str } \str_if_exist:NF - \g__luabridge_error_output_filename_str + \g_luabridge_error_output_filename_str { \str_gset_eq:NN - \g__luabridge_error_output_filename_str - \c__luabridge_default_error_output_filename_str + \g_luabridge_error_output_filename_str + \c_luabridge_default_error_output_filename_str } \str_if_exist:NF - \g__luabridge_standard_output_filename_str + \g_luabridge_standard_output_filename_str { \str_gset_eq:NN - \g__luabridge_standard_output_filename_str - \c__luabridge_default_standard_output_filename_str + \g_luabridge_standard_output_filename_str + \c_luabridge_default_standard_output_filename_str } \cs:w newwrite \cs_end: \l__luabridge_output_stream \cs_new:Nn - \_luabridge_execute:n + \luabridge_now:n { \immediate \openout \l__luabridge_output_stream - \g__luabridge_helper_script_filename_str + \g_luabridge_helper_script_filename_str \msg_info:nnV { luabridge } { writing-helper-script } - \g__luabridge_helper_script_filename_str - \tl_set:Nx + \g_luabridge_helper_script_filename_str + \tl_set:Nn \l_tmpa_tl + { #1 } + \tl_set:Nx + \l_tmpb_tl { local~ran_ok,~error~=~pcall(function()~ local~ran_ok,~kpse~=~pcall(require,~"kpse")~ if~ran_ok~then~kpse.set_program_name("luatex")~end~ - #1~ + \exp_not:V \l_tmpa_tl~ end)~ if~not~ran_ok~then~ local~file~=~io.open(" - \g__luabridge_output_dirname_str / - \g__luabridge_error_output_filename_str + \g_luabridge_output_dirname_str / + \g_luabridge_error_output_filename_str ",~"w")~ if~file~then~ file:write(error~..~" \iow_char:N \\ n ")~ @@ -304,37 +373,37 @@ \iow_char:N \\ \iow_char:N \\ msg_error:nnvv { luabridge } { failed-to-execute } - { g__luabridge_output_dirname_str } - { g__luabridge_output_dirname_str } + { g_luabridge_output_dirname_str } + { g_luabridge_output_dirname_str } \iow_char:N \\ \iow_char:N \\ endgroup ')~ end } \immediate \write \l__luabridge_output_stream - { \exp_not:V \l_tmpa_tl } + { \exp_not:V \l_tmpb_tl } \immediate \closeout \l__luabridge_output_stream \msg_info:nnVV { luabridge } { executing-helper-script } - \g__luabridge_helper_script_filename_str - \g__luabridge_standard_output_filename_str + \g_luabridge_helper_script_filename_str + \g_luabridge_standard_output_filename_str \tl_set:Nx \l_tmpa_tl { texlua~" - \g__luabridge_output_dirname_str / - \g__luabridge_helper_script_filename_str + \g_luabridge_output_dirname_str / + \g_luabridge_helper_script_filename_str "~>~" - \g__luabridge_output_dirname_str / - \g__luabridge_standard_output_filename_str + \g_luabridge_output_dirname_str / + \g_luabridge_standard_output_filename_str " } \_luabridge_execute_shell:V \l_tmpa_tl \file_if_exist_input:VF - \g__luabridge_standard_output_filename_str + \g_luabridge_standard_output_filename_str { \msg_error:nn { luabridge } @@ -382,9 +451,13 @@ } { \cs_new:Nn - \_luabridge_execute:n + \luabridge_now:n { - \directlua + \tl_set:Nn + \l_tmpa_tl + { #1 } + \tl_set:Nx + \l_tmpb_tl { local~function~print(input)~ input~=~tostring(input)~ @@ -397,11 +470,26 @@ end~ tex.print(output)~ end~ - #1 + \exp_not:V \l_tmpa_tl } + \lua_now:V + \l_tmpb_tl } + \cs_generate_variant:Nn + \lua_now:n + { V } } \cs_new_protected:Npn \luabridgeExecute - { \_luabridge_execute:n } + #1 + { + \luabridge_now:e + { #1 } + } +\cs_generate_variant:Nn + \luabridge_now:n + { e } \ExplSyntaxOff +\endinput +%% +%% End of file `lt3luabridge.tex'. diff --git a/Master/texmf-dist/tex/generic/lt3luabridge/t-lt3luabridge.tex b/Master/texmf-dist/tex/generic/lt3luabridge/t-lt3luabridge.tex index 12f8b18aff9..f142d0965f5 100644 --- a/Master/texmf-dist/tex/generic/lt3luabridge/t-lt3luabridge.tex +++ b/Master/texmf-dist/tex/generic/lt3luabridge/t-lt3luabridge.tex @@ -1,4 +1,51 @@ +%% +%% This is file `t-lt3luabridge.tex', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% lt3luabridge.dtx (with options: `context-package') +%% +%% Copyright (C) 2016-2022 Vít Novotný +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3c +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% +%% http://www.latex-project.org/lppl.txt +%% +%% This work has the LPPL maintenance status `maintained'. +%% The Current Maintainer of this work is Vít Novotný. +%% +%% Send bug reports, requests for additions and questions +%% either to the GitHub issue tracker at +%% +%% https://github.com/Witiko/lt3luabridge/issues +%% +%% or to the e-mail address . +%% +%% MODIFICATION ADVICE: +%% +%% If you want to customize this file, it is best to make a copy of +%% the source file(s) from which it was produced. Use a different +%% name for your copy(ies) and modify the copy(ies); this will ensure +%% that your modifications do not get overwritten when you install a +%% new release of the standard system. You should also ensure that +%% your modified source file does not generate any modified file with +%% the same name as a standard file. +%% +%% You will also need to produce your own, suitably named, .ins file to +%% control the generation of files from your source file; this file +%% should contain your own preambles for the files it generates, not +%% those in the standard .ins files. +%% +%% The names of the source files used are shown above. +%% \writestatus{loading}{ConTeXt User Module / lt3luabridge} \startmodule[lt3luabridge] \unprotect \input lt3luabridge\relax +\endinput +%% +%% End of file `t-lt3luabridge.tex'. -- cgit v1.2.3