Re: MPlib: detect bye/end

luigi scarso <[email protected]>
Newsgroups gmane.comp.tex.metapost
Message-ID <CAG5iGsA2_XE6M49et1yt-JP7dKE5duXEiAqw1eSf3p5A-Ls7jA@mail.gmail.com>
On Thu, Dec 15, 2016 at 3:23 PM, Nicola <[email protected]> wrote:
> On 15/12/2016 12:48, luigi scarso wrote:
> What I'm doing now is somewhat simpler:
>
>       mp_execute(imp, "\\", 1); // Send a token that expands to nothing
>       mp_run_data *cmd_result = mp_rundata(imp);
>       if (!cmd_result || !cmd_result->term_out.size) {
>         return 0; // Quit
>       }
>
> This seems to work, but I guess that it is not robust enough. In which case
> would it fail to recognize that it's time to quit (please note that I'm
> using this in a REPL)?

@ @c
mp_run_data *mp_rundata (MP mp) {
  return &(mp->run_data);
}

hence cmd_result can be not NULL after an 'end'; checking the size is
not enough, because the empty string has size 0 but it's still a
string.

-- 
luigi
--
http://tug.org/metapost/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.