[metapost] MPlib: detect bye/end

luigi scarso luigi.scarso at gmail.com
Thu Dec 15 20:32:21 CET 2016


On Thu, Dec 15, 2016 at 3:23 PM, Nicola <nvitacolonna at gmail.com> 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


More information about the metapost mailing list