WSPutFunction (C 函数)

int WSPutFunction(WSLINK link,const char *s,int n)

把一个标头由名称为 s,并带有 n 个自变量的符号给定的函数写入由 link 指定的 WSTP 连接.

更多信息

  • 在调用 WSPutFunction() 之后,必须调用其他 WSTP 函数传递函数的自变量.
  • 若发生错误,则 WSPutFunction() 返回0;若函数成功,则返回非零值.
  • 如果 WSPutFunction() 失败,则使用 WSError() 检索错误代码.
  • WSTP 的标头文件 wstp.h 已对 WSPutFunction() 作出声明.

范例

基本范例  (1)

#include "wstp.h"

/* put an Integrate[] expression to a link */

void f(WSLINK lp)
{
    if(! WSPutFunction(lp, "Integrate", 2))
        { /* unable to put the function to lp */ }

    if(! WSPutFunction(lp, "Times", 2))
        { /* unable to put the function to lp */ }

    if(! WSPutFunction(lp, "Power", 2))
        { /* unable to put the function to lp */ }

    if(! WSPutSymbol(lp, "x", 1))
        { /* unable to put the symbol to lp */ }

    if( ! WSPutInteger(lp, 2))
        { /* unable to put the integer to lp */ }

    if(! WSPutFunction(lp, "Power", 2))
        { /* unable to put the function to lp */ }

    if(! WSPutFunction(lp, "Sqrt", 1))
        { /* unable to put the function to lp */ }

    if(! WSPutSymbol(lp, "x", 1))
        { /* unable to put the symbol to lp */ }

    if(! WSPutInteger(lp, -1))
        { /* unable to put the integer to lp */ }

    if(! WSPutSymbol(lp, "x", 1))
        { /* unable to put the symbol to lp */ }

    if(! WSEndPacket(lp))
        { /* unable to send the end-of-packet sequence to lp */ }

    if(! WSFlush(lp))
        { /* unable to flush any buffered output data in lp */ }
}