It seem there's this promising function in the callback object provided to MathLink C functions:

struct st_WolframLibraryData
    /* ... */
    int (*evaluateExpression)(WolframLibraryData, char *, int, mint, void *);
    /* ... */

If this does what it seems it does, it would save the boring and lengthy code that comes with managing a MLINK object for some purpose. But I'm lost at interpreting the arguments (and if the second one is supposedly the string to execute, why is it not const?).

  • $\begingroup$ The internal structure of a parsed expression is more like an Internal`Bag, not a string. So I wouldn't like to guess what kind of inputs this thing requires. $\endgroup$ May 5, 2014 at 15:23

1 Answer 1


I have done a brief reverse engineering, and this is the result.

Here's how to interpret the function:

int // 0 = LIBRARY_NO_ERROR for success, 6 = LIBRARY_FUNCTION_ERROR for bad syntax
evaluateExpression(WolframLibraryData _ignored, char* expression, int ResultType, mint ResultStuff1, void* ResultStuff2);

So the problem is that the function tries to store the result of the expression in some internal format using the last two arguments... unless ResultType == 6.

So, this wrapper comes handy if you want to evaluate some hardcoded expressions in your C library:

int MathematicaEval(WolframLibraryData wd, const char* expression){
    return wd->evaluateExpression(0, (char*)(expression), 6, 0, 0);
  • 1
    $\begingroup$ Result type = 6 means a "normal expression", a compound non-atomic expression (like "Plus[a, 2]"). $\endgroup$
    – JavierG
    Aug 23, 2016 at 21:13

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.