MLPutRawSize (C 函数)

MLPutRawSize 已经被 WSPutRawSize 所取代.

int MLPutRawSize(MLINK link, int s)

准备 link 接受 s 个字节的原始字符数据或数值数据.

更多信息

  • 使用 MLPutRawSize() 以及 MLPutType()MLPutRawData() 手动把数据写入链接,而不是使用特定类型的 API 函数例如 MLPutInteger32()MLPutUTF8String().
  • MLPutRawSize() 在错误事件中返回0,如果函数成功则返回非零值.
  • 如果 MLPutRawSize() 失败,则使用 MLError() 检索错误代码.
  • MLPutRawSize() 在 MathLink 标头文件 mathlink.h 中被声明.

范例

基本范例  (1)

#include "mathlink.h"

/* send a function as raw data to a link */

void f(MLINK lp)
{
    int a = 2, b = 3;

    if(! MLPutType(lp, MLTKFUNC))
        { return; /* unable to put the function type to lp */ }

    if(! MLPutArgCount(lp, 2))
        { return; /* unable to put the number of arguments to lp */ }

    if(! MLPutType(lp, MLTKOLDSYM))
        { return; /* unable to put function head type to lp */ }
    
    if(! MLPutRawSize(lp, 4))
        { return; /* unable to put the size of the symbol to lp */ }

    if(! MLPutRawData(lp, (const unsigned char *)"Plus", 4))
        { return; /* unable to put the raw bytes to lp */ }

    if(! MLPutType(lp, MLTK_CINT))
        { return; /* unable to put the argument type to lp */ }

    if(! MLPutRawSize(lp, sizeof(int)))
        { return; /* unable to put the size of the integer to lp */ }

    if(! MLPutRawData(lp, (const unsigned char *)&a, sizeof(a)))
        { return; /* unable to put the raw bytes of a to lp */ }

    if(! MLPutType(lp, MLTK_CINT))
        { return; /* unable to put the second argument type to lp */ }

    if(! MLPutRawSize(lp, sizeof(int)))
        { return; /* unable to put the size of the integer to lp */ }

    if(! MLPutRawData(lp, (const unsigned char *)&b, sizeof(b)))
        { return; /* unable to put the raw bytes of b to lp */ }
}