If I compile the following code with LuaLaTeX I get the word "RED" as output. The call of token.set_macro inside of luacode* seems to be noneffective.
\listfiles
\documentclass{minimal}
\usepackage{luacode}
\newcommand*\foo{RED}
\iftrue
\begin{luacode*}
token.set_macro('foo', 'GREEN')
\end{luacode*}
\else
\directlua{token.set_macro('foo', 'GREEN')}
\fi
\begin{document}
\foo
\end{document}
After changing \iftrue to \iffalse I get "GREEN". Can anyone explain this behavior? Many thanks.
tex.printto print the\defto TeX) – user202729 Jan 06 '22 at 06:27