1
$\begingroup$

Consider that Func is a function written in c language by using WSTP library. In some situations, it can return an error to Mathematica.

void Func()
{
   ...
   WSPutSymbol(stdlink, "$Failed");
}

In addition to show a $Failed message, I want to show an error message (a red colored message). How can I do this?

$\endgroup$
2
  • $\begingroup$ Section 1.6 in the tutorial I suggested to you. $\endgroup$
    – Szabolcs
    Commented Aug 31, 2018 at 13:58
  • $\begingroup$ Here is an example of sending a message from a library: stackoverflow.com/a/6527191/4712538 $\endgroup$
    – Jason B.
    Commented Aug 31, 2018 at 13:58

1 Answer 1

2
$\begingroup$

The tutorial I suggested to you has a complete example. See section 1.6. Please read through the entire first chapter.


Here's a copy of the code from there:

In your template file, ensure that both argument passing and return are set to Manual, then add the following:

:Evaluate: AddTwo::ovflw = "The sum cannot fit into a C long type."

A modification of the addtwo example:

void addtwo(void) {
   long i, j, sum;
   MLGetLongInteger(stdlink, &i);
   MLGetLongInteger(stdlink, &j);
   sum = i + j;
   if(i>0 && j>0 && sum<0 || i<0 && j<0 && sum>0) {
     MLEvaluate(stdlink, "Message[AddTwo::ovflw]");
     MLNextPacket(stdlink);
     MLNewPacket(stdlink);
     MLPutSymbol(stdlink, "$Failed");
   } else {
     MLPutLongInteger(stdlink, sum);
   }
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.