WSUserData (C 関数)

void * WSUserData(WSLINK link,WSUserFunction *fp)

WSSetUserData()でインストールされたデータオブジェクトと関数ポインタを返す.

詳細

  • WSUserData()は,WSTPヘッダファイルwstp.hの中で宣言される.

例題

  (1)

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

typedef struct foo_ {
    int member;
} foo;


int main(int argc, char **argv)
{
    WSENV env;
    WSLINK link;
    int error;
    foo *fobj;

    fobj = (foo *)malloc(sizeof(foo));
    if(fobj == (foo *)0)
        { /* unable to allocate memory for foo object */ }

    env = WSInitialize((WSEnvironmentParameter)0);
    if(env == (WSENV)0)
        { /* unable to initialize WSTP environment */ }

    link = WSOpenArgcArgv(env, argc, argv, &error);
    if(link == (WSLINK)0 || error != WSEOK)
        { /* unable to create link object */ }

    WSSetUserData(link, (void *)fobj, (WSUserFunction)0);

    /* ... */

    fobj = WSUserData(link, (WSUserFunction *)0);

    free(fobj);

    WSClose(link);
    WSDeinitialize(env);

    return 0;
}