WSSetUserData (C Function)
void WSSetUserData(WSLINK link,void* d,WSUserFunction f)
installs the users data object data and function f in link.
Details
- 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.
Examples
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(WSLINK 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(WSLINK lp)
{
foo *fobj;
fobj = (foo *)malloc(sizeof(foo));
if(fobj == (foo *)0)
{ /* error allocating space for foo object */ }
WSSetUserData(lp, (void *)fobj, c);
}