I store contents in lua variables and use them in a lualatex document. I know how to do insert that content in the TeX flow, in a macro but I don't know how to launch a lua program contained in a lua variable.
\documentclass{article}
\usepackage{luatextra} % pour LuaLaTex
\begin{document}
\newcommand{\amacro}[1]{*#1*}
\luaexec{
a=1
atext='stupid text'
apgm='a=a+1' % the content is a program
}
\luaexec{tex.print(atext)} % contents in the TeX flow : works
\amacro{\luaexec{tex.print(atext)}} % contents used in a macro : works
\luaexec{\luaexec{tex.print(apgm)}} % contents used as a program : fails
\luaexec{tex.print(a)}
\end{document}
How shall I launch the lua program stored in the lua variable apgm ?
\documentclass
line and a definition for\luaexec
and\lprint
\directlua
is expandable so more easily nested in this way, but storing the lua expression in a lua string and passing back to tex to be re-evaluated as lua is somewhat unusual (and means you will have lots of issues of quoting any characters special to tex or lua) , what is the actual use case?function apgm (a) return a+1 end
?\directlua
/\luaexec
is basically as described in answers to your earlier question tex.stackexchange.com/questions/284748/… where as egreg explained there,\luaexec
is not expandable. But here I do not think you needed nested eval at all.