I'd like to feed a lstlisting environment (from the listings
package) with contents back to TeX from Lua, but the end of lstlisting is apparently not found. The same happens if lstlisting is replaced with verbatim. How do I fix this?
Note that I want luacode to feed lstlisting back to TeX, not a hack that works in this instance but doesn't do that.
\documentclass{article}
\usepackage{listings}
\usepackage{luacode,luatexbase}
\newcommand{\processfile}[1]{\directlua{processfile("#1")}}
\begin{luacode*}
function processfile(fn)
tex.print("\\begin{lstlisting}\n")
local f=assert(io.open(fn,"r"))
local t= f:read("*all")
f:close()
tex.print(t)
tex.print("\\end{lstlisting}\n")
end
\end{luacode*}
\begin{document}
\processfile{code.c}
\end{document}
tex.print("\\scantokens{\end{lstlisting}\n")
help?