WSSetUserData()
This feature is not supported on the Wolfram Cloud.

void WSSetUserData(WSLINK link,void* d,WSUserFunction f)
installs the users data object data and function f in link.

DetailsDetails

  • The object d is retrievable anytime using WSUserData().
  • WSTP will automatically call the function f at WSClose() time with link as its argument.
  • WSSetUserData() is declared in the WSTP header file wstp.h.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

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

typedef struct foo_
{
    int member1;
} foo;


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

    fobj = WSUserData(lp, (WSUserFunction *)0);
    if(fobj == (foo *)0) return;

    free(foo);
}


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

void f(WSINK lp)
{
    foo *fobj;

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

    WSSetUserData(lp, (void *)fobj, c);
}