Skip to content

Commit

Permalink
Add \newluacmd & \newprotectedluacmd
Browse files Browse the repository at this point in the history
  • Loading branch information
zauguin committed Nov 15, 2021
1 parent 2feea85 commit c1430f3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
27 changes: 27 additions & 0 deletions base/ltluatex.dtx
Expand Up @@ -120,6 +120,17 @@
% tables from $1$ so |\luafunction0| is not available).
%
% \noindent
% \DescribeMacro{\newluacmd}
% |\newluadef{|\meta{function}|}|\\
% Like \cs{newluafunction}, but defines the command using \cs{luadef}
% instead of just assigning an integer.
%
% \noindent
% \DescribeMacro{\newprotectedluacmd}
% |\newluadef{|\meta{function}|}|\\
% Like \cs{newluacmd}, but the defined command is not expandable.
%
% \noindent
% \DescribeMacro{\newwhatsit}
% |\newwhatsit{|\meta{whatsit}|}|\\
% Defines a custom \cs{whatsit}, indexed from~$1$.
Expand Down Expand Up @@ -722,6 +733,22 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\newluacmd, \newprotectedluacmd}
% \changes{v?.?}{2021/03/22}{Macros added}
% Additionally two variants are provided to make the passed control
% sequence call the function directly.
% \begin{macrocode}
\def\newluacmd{%
\e@alloc\luafunction\luadef
\e@alloc@luafunction@count\m@ne\e@alloc@top
}
\def\newprotectedluacmd{%
\e@alloc\luafunction{\protected\luadef}
\e@alloc@luafunction@count\m@ne\e@alloc@top
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Custom whatsits}
%
% \begin{macro}{\newwhatsit}
Expand Down
5 changes: 2 additions & 3 deletions base/ltoutenc.dtx
Expand Up @@ -2949,14 +2949,14 @@
\endgroup
}
\else
\newluafunction\@remove@tlig@@@@
\newprotectedluacmd\@remove@tlig@@@
% \end{macrocode}
% Now we can define the function. Mostly we just have to insert a protected glyph
% node, which is a glyph node with subtype 256. But we have to keep track of the
% current mode to avoid inserting the glyph into a vlist.
% \begin{macrocode}
\now@and@everyjob{\directlua{
local rawchar_func = token.create'@remove@tlig@@@@'.index
local rawchar_func = token.create'@remove@tlig@@@'.index
local forcehmode = tex.forcehmode
local put_next = token.put_next
local glyph_id = node.id'glyph'
Expand All @@ -2972,7 +2972,6 @@
n.char = token.scan_int()
return node.write(n)
end
token.set_lua('@remove@tlig@@@', rawchar_func, 'global', 'protected')
}}
% \end{macrocode}
% Now \verb+\remove@tlig+ can be implemented almost as in XeTeX.
Expand Down
5 changes: 2 additions & 3 deletions base/ltshipout.dtx
Expand Up @@ -734,21 +734,20 @@
% \begin{macrocode}
\sys_if_engine_luatex:TF
{
\newluafunction \@@_finalize_box:
\newprotectedluacmd \@@_finalize_box:
\exp_args:Nx \everyjob {
\exp_not:V \everyjob
\exp_not:N \lua_now:n {
luatexbase.create_callback('pre_shipout_filter', 'list')
local~call, getbox, setbox = luatexbase.call_callback, tex.getbox, tex.setbox~
lua.get_functions_table()[\the \@@_finalize_box:] = function()
lua.get_functions_table()[\the \allocationnumber] = function()
local~result = call('pre_shipout_filter', getbox(\the \l_shipout_box))
if~not (result == true) then~
setbox(\the \l_shipout_box, result~or~nil)
end~
end
}
}
\protected \luadef \@@_finalize_box: \the \@@_finalize_box:
} {
\cs_set_eq:NN \@@_finalize_box: \scan_stop:
}
Expand Down

0 comments on commit c1430f3

Please sign in to comment.