MLPutRawData (C 関数)

MLPutRawDataWSPutRawDataに置き換えられた.

int MLPutRawData(MLINK link, const unsigned char *d, int l)

長さがl バイトでd からの未加工の文字データあるいは数値データをlink に置く.

詳細

  • MLPutRawData()MLPutType()MLPutRawSize()と一緒に使うと,MLPutInteger32()あるいはMLPutUTF8String()等の型特定のAPI関数を使わずに手入力でデータをリンクに置くことができる.
  • MLPutRawData()を使って数値データを送信すると,異種のコンピュータシステム間のデータの互換性を確保するMathLinkライブラリ内部構造を通らずに送信される.この関数を使うためには,ユーザはコンピュータシステム間のエンディアンネスとC言語の型のサイズの違いを考慮する必要がある.
  • 文字データを送信する場合は,MLPutType()を文字列データについてはトークン引数MLTKOLDSTRと一緒に,記号データについてはトークン引数MLTKOLDSYMと一緒に使うとよい.MLPutRawData()を使って7ビットのASCIIコード化形式以外の形式の文字データを送信してはならない.
  • 数値データを送信する場合は,バイナリデータ用の正しいトークンと一緒にMLPutType()を使うとよい.MathLinkヘッダファイル mathlink.h にこれらのトークンの完全なリストが含まれているが,ここに便宜上よく使われるトークンを挙げておく.
  • unsigned charMLTK_CUCHAR
    shortMLTK_CSHORT
    intMLTK_CINT
    longMLTK_CLONG
    floatMLTK_CFLOAT
    doubleMLTK_CDOUBLE
    long doubleMLTK_CLONGDOUBLE
  • MLPutRawData()はエラーがあると0を返し,関数が成功するとゼロ以外の値を返す.
  • MLError()を使うと,MLPutRawData()が不成功の場合にエラーコードを引き出すことができる.
  • MLPutRawData()は,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 */ }
}