This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
MathLink C Function

MLUserFunction

MLUserFunction
is a MathLink type that describes a function pointer to a function taking an MLINK argument with a return type of void.
  • 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.
#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);
}