[metapost] Can I use interactive mode in Lua?

Rui Zhang zrui16 at hotmail.com
Sun Oct 15 21:51:36 CEST 2017


On Oct 15 16:06:50, Hans Hagen wrote:
>when a macro package uses the library then it has to make sure it 
>reports the errors which are available in the result table

Sorry, I don't get it. I mean if I have some errors in the
metapost source, the standalone mpost program will stop
at the first error and ask me what to do, and for example
I can type X to terminate it.
With mplib, it will not stop and always generating all errors.

Here is what I tried.  I used mplib directly in Lua, so it has
nothing to do with macro packages.

    local mpkpse = kpse.new('mpost')
    local mp = mplib.new {
      job_name='mpout',
      find_file = function(name, mode, type_)
        if mode == 'r' then
          return mpkpse:find_file(name, type_)
        end
        return name
      end,
    }
    res = mp:execute [[
    input plain;
    beginfig(1);
      draw error % this line contains an error
      draw fullcircle;
    endfig;
    ]]
    print(res.term)

I got:

This is MetaPost, Version 2.000
 (d:/texlive/2017/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005)


>> error
! Improper `addto'.
<to be read again>
                   withpen
draw->...:also(EXPR0)else:doublepath(EXPR0)withpen
                                                  .currentpen.fi._op_
<to be read again>
                   addto
draw->addto
           .currentpicture.if.picture(EXPR0):also(EXPR0)else:doublepath(EXPR...
<to be read again>
                   ;
<*>       draw fullcircle;

This expression should have specified a known path.
So I'll not change anything just now.

! Extra tokens will be flushed.
<to be read again>
                   addto
draw->addto
           .currentpicture.if.picture(EXPR0):also(EXPR0)else:doublepath(EXPR...
<to be read again>
                   ;
<*>       draw fullcircle;

I've just read as much of that statement as I could fathom,
so a semicolon should have been next. It's very puzzling...
but I'll try to get myself back together, by ignoring
everything up to the next `;'. Please insert a semicolon
now in front of anything that you don't want me to delete.
(See Chapter 27 of The METAFONTbook for an example.)

(EOF)

This is too much for me.  It did not stop and kept
processing the remaining of the code.
If I use standalone mpost, I get

This is MetaPost, version 2.000 (TeX Live 2017/W32TeX) (kpathsea version 6.2.3)
(d:/texlive/2017/texmf-dist/metapost/base/mpost.mp (d:/texlive/2017/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./mpost1.mp
>> error
! Improper `addto'.
<to be read again>
                   withpen
draw->...:also(EXPR0)else:doublepath(EXPR0)withpen
                                                  .currentpen.fi._op_
<to be read again>
                   addto
draw->addto
           .currentpicture.if.picture(EXPR0):also(EXPR0)else:doublepath(EXPR...
<to be read again>
                   ;
l.3   draw fullcircle;

?

which stops at the first error and gives an interactive prompt.



More information about the metapost mailing list