I want to set a box register so I use \setbox180=\hbox{TEST}
under the function tex.print and then use
directlua to get its width. So This programme:
\documentclass{article}
\usepackage{luacode}
\begin{document}
\directlua{
function w(obj)
if obj == nil then
return "nil"
else
return obj.width
end
end
}
I make three box that have widthes in%
\setbox200=\hbox{TEST AND TEST}%
\directlua{
tex.print("\string\setbox180=\string\hbox{AB}")
tex.print(w(tex.box[180]).." sp and "..w(tex.box[200]).."sp")
}.
I make two box that have widthes in
\directlua{
tex.print(w(tex.box[180]).." sp and "..w(tex.box[200]).."sp")
}.
\end{document}
But the output is:
I make three box that have widthes in nil sp and 5434245sp.
I make two box that have widthes in 955515 sp and 5434245sp.
that means that the box in the directlua cannot be made in time
but after when it exits the command.
How can I make it? Is there other ways to assign the box register?
Thank you a lot.
(I edit it to make it run. Concurrently interleaving execution of Lua and TeX in LuaTeX looks have the answer that I want)
\luaderictlooks like a typo. Does your code actually run? – Mico Jun 08 '20 at 05:24\luadirectyour code says\luaderictbut neither of those commands are defined by default in lualatex. – David Carlisle Jun 08 '20 at 07:34>_<– Peterlits Zo Jun 12 '20 at 08:12