Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 at 15:23

1 Answer 1

up vote 3 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

 
discard

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.