Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?).

share|improve this question
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. – Oleksandr R. May 5 '14 at 15:23
up vote 4 down vote accepted

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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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