MLBytesToPut (C 関数)

MLBytesToPutWSBytesToPutに置き換えられた.

int MLBytesToPut(MLINK link,int *n)

現行データのテキスト表現の中にまだ書き込まれていないバイト数を計算し,その結果をn に保存する.

詳細

  • MathLink は文字列,シンボル,整数,浮動小数点数を送るために,MLPutString()MLPutSymbol()MLPutInteger32(),MLPutReal64()等の関数を供給する.しかし文字列表示を使ってこれらの形式のものを送るほうが便利な場合もときにはある.MLBytesToPut()は,MLPutType(),MLPutRawSize()MLPutRawData()を使って,文字列表示を使う形式のものを送ることができる.
  • MLBytesToPut()はエラーがあると0を返し,関数が成功すると0以外の値を返す.
  • MLError()を使うと,MLBytesToPut()が不成功の場合にエラーコードを引き出すことができる.
  • MLBytesToPut()は,MathLinkヘッダファイル mathlink.hの中で宣言される.

例題

  (1)

#include <string.h>
#include "mathlink.h"

/* send an approximation of Pi across a link */

void f(MLINK lp)
{
    char *Pi = "3.141592654";
    int bytes_left, i;

    if(! MLPutType(lp, MLTKOLDREAL))
        { /* unable to send the data type to lp */ }

    if(! MLPutRawSize(lp, strlen(Pi))
        { /* unable to send the length of Pi to lp */ }

    if(! MLBytesToPut(lp, &bytes_left))
        { /* unable to get the remaining bytes to send from lp */ }

    i = 0;
    while(bytes_left > 0)
    {
        /* send the data one byte at a time */
        if(! MLPutRawData(lp, Pi + i, 1))
            { /* unable to send a character of Pi to lp */ }

        if(! MLBytesToPut(lp, &bytes_left))
            { /* unable to get the remaining bytes to send from lp */ }

        i++;
    }
}