[CM] Examples of printing out errors in S7?

Iain Duncan iainduncanlists at gmail.com
Fri Apr 10 19:53:25 PDT 2020


Thanks Bill, the example in grepl.c is working fine for me now. I had been
calling s7_load without checking the error port.

I do have a question, if you have time to answer. What is the reason we
need to do the gc_protect and later unprotect of the old port? If it's not
something simple to explain, pointers at where I can learn more about that
would be helpful too.

thanks for the help,
iain

On Fri, Apr 10, 2020 at 10:37 AM Iain Duncan <iainduncanlists at gmail.com>
wrote:

> Thanks Bill, I'll chew on all that and see how far I can get. Much
> appreciated.
>
> iain
>
> On Fri, Apr 10, 2020 at 10:15 AM <bil at ccrma.stanford.edu> wrote:
>
>> Normally, s7_error (called either from C or scheme) sends its error
>> message
>> to the current error-port.  It defaults to *stderr*, so in GUI-based
>> apps,
>> you may need to redirect the output to your interface.  One example is
>> s7/tools/grepl.c.  Its evaluator function wraps up the s7_eval_c_string:
>>
>>    old_port = s7_set_current_error_port(s7, s7_open_output_string(s7));
>>    ...
>>    result = s7_eval_c_string(s7, text);
>>    errmsg = s7_get_output_string(s7, s7_current_error_port(s7));
>>    ...
>>
>> and if errmsg is not NULL, it posts it somewhere (via
>> glistener_append_text,
>> since it's using the repl in glistener.c).  Snd uses largely the same
>> code (snd-motif.c and glistener.c if in gtk).  See also s7.html under
>> "glistener".  If you don't want s7's error messages, you can go down
>> a level via *error-hook*.
>>
>> I don't know why your program exits silently, but a first fix might be
>> to wrap the string being evaluated in a catch (s7.html under "errors").
>> If you're calling s7_apply_function, you may need to make sure
>> a catch exists.  In Snd, if I remember right, this involves
>> top_level_catch (snd.c, snd-nogui.c, etc).  Or you can use s7_call
>> instead of s7_apply_function.
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20200410/a1b185e1/attachment.html>


More information about the Cmdist mailing list