% This is the main TeX file for the Interpreter package.
% Further information in interpreter-doc.pdf or interpreter-doc.txt.
%
% Paul Isambert - zappathustra AT free DOT fr - December 2011
%
\csname Oh no, Interpreter won't be loaded twice!\endcsname
\expandafter\let\csname Oh no, Interpreter won't be loaded twice!\endcsname\endinput
\directlua{require("interpreter.lua")}
\def\interpretergobble#1{}
\unless\ifdefined\interpreterinput
  \let\interpreterinput\input
\fi
\def\interpretfile#1#2{%
  \directlua{%
    local f = kpse.find_file("i-#1.lua")
    if f then
      interpreter.reset()
      dofile(f)
      if interpreter.type"register" == 0 then
        if luatexbase and luatexbase.add_to_callback then
          function interpreter.register (f)
            luatexbase.add_to_callback("open_read_file", f, "interpreter")
          end
        else
          function interpreter.register (f)
            callback.register("open_read_file", f)
          end
        end
      end
      interpreter.register(interpreter.core.reader.input)
      tex.print([[\noexpand\interpreterinput]])
    else
      tex.error("I can't find file `i-#1.lua'. I won't input file `#2'")
      tex.print([[\noexpand\interpretergobble]])
    end
    }{#2}%
  }
