MLUserFunction


is a MathLink type that describes a function pointer to a function taking an MLINK argument with a return type of void.

DetailsDetails

  • The function MLSetUserData() takes a MLUserFunction as its second argument. MathLink automatically calls the MLUserFunction at MLClose() time.
  • MLUserFunction is declared in the MathLink header file mathlink.h.

ExamplesExamplesopen allclose all

Basic Examples (1)Basic Examples (1)

#include <stdlib.h>
#include "mathlink.h"

typedef struct foo_
{
    int member1;
} foo;


/* destroy a foo object retrieved from a link */
void c(MLINK lp)
{
    foo *fobj;

    fobj = MLUserData(lp, (MLUserFunction *)0);
    if(fobj == (foo *)0) return;

    free(foo);
}


/* allocate a foo object and store it in a link */

void f(MLINK lp)
{
    foo *fobj;

    fobj = (foo *)malloc(sizeof(foo));
    if(fobj == (foo *)0)
        { /* error allocating space for foo object */ }

    MLSetUserData(lp, (void *)fobj, c);
}
New to Mathematica? Find your learning path »
Have a question? Ask support »