[luatex] File I/O.

Paul Isambert zappathustra at free.fr
Sat Jul 31 00:52:13 CEST 2010

Selon luigi scarso <luigi.scarso at gmail.com>:

> On Fri, Jul 30, 2010 at 10:36 PM, Paul Isambert <zappathustra at free.fr> wrote:
> > Hello all,
> >
> > I'm sure I must have missed something in the manual. I'm totally unable to
> find
> > a way to say something like \write5{whatever} in a lua way. The texio.write
> > function writes only to the terminal or log, and my attempts at hooking lua
> > functions such as <file>:write() with <file> defined in a find_write_file
> > callback are unsuccessful, since it works iff I don't also write to the
> file
> > with TeX's \write.
> >
> > So, to produce an intelligible question: how do you write to an external
> file
> > with in \directlua, or what is the lua equivalent of \write?
> Perhaps
> fd = io.open("mfyfile","wb")
> fd:write(values)
> fd:close()

Thank you Luigi, but it doesn't work: TeX's \write calls and the Lua calls are
incompatible, and the former overwrites the latter, unless "fd:close()" isn't
given, in which case Lua overwrites TeX.

Actually I can make do with

  writetofile = function (message)
    tex.print("\luaescapestring{\write\test}{" .. message .. "}")

but it really seems archaic in view of what LuaTeX usually does. So does this
means there's no function like "tex.filewrite(n,message)" that would be totally
equivalent to (and compatible with) \write<n>{<message>}? I find it quite hard
to believe, which is why I still think I must have missed something in the


More information about the luatex mailing list