3

ActionScript から C 関数に ByteArray を渡したい。

基本的に私はこのようなことをしたい:

void init() __attribute__((used,annotate("as3sig:public function init(byteData: ByteArray):int"),
        annotate("as3package:example")));

void init()
{
   //here I want to pass byteArray data to C variable.
   //similar to AS3_GetScalarFromVar(cVar, asVar) 
}

残念ながら、flascc ドキュメントには、これを支援する関数が見つかりません。

4

3 に答える 3

4

例:

void _init_c(void) __attribute((used,
    annotate("as3sig:public function init(byteData:ByteArray) : void"),
    annotate("as3import:flash.utils.ByteArray")));

void _init_c()
{
    char *byteArray_c;
    unsigned int len;

    inline_as3("%0 = byteData.bytesAvailable;" : "=r"(len));
    byteArray_c = (char *)malloc(len);

    inline_as3("CModule.ram.position = %0;" : : "r"(byteArray_c));
    inline_as3("byteData.readBytes(CModule.ram);");

    // Now byteArray_c points to a copy of the data from byteData.
    // Note that byteData.position has changed to the end of the stream.

    // ... do stuff ...

    free(byteArray_c);
}

ここで重要なのは、C のヒープがオブジェクトCModule.ramであるとして AS3 側に公開されているByteArrayことです。

C で malloc されたポインタは、AS3 では へのオフセットとして認識されCModule.ramます。

于 2013-02-20T23:33:17.923 に答える
2

CModule.malloc および CModule.writeBytes メソッドを使用して、C スタイルの方法でポインターを操作する必要があります。$FLASCC/samples/06_SWIG/PassingData/PassData.as を見てください。

于 2013-01-27T10:39:13.300 に答える
-1
void _init_c(void) __attribute((used,
    annotate("as3sig:public function init(byteData:ByteArray) : void"),
    annotate("as3import:flash.utils.ByteArray")));

void _init_c()
{
    char *byteArray_c;
    unsigned int len;

    inline_as3("%0 = byteData.bytesAvailable;" : "=r"(len));
    byteArray_c = (char *) malloc(len);

    inline_as3("byteData.readBytes(CModule.ram, %0, %1);" : : "r"(byteArray_c), "r"(len));

    // Now byteArray_c points to a copy of the data from byteData.
    // Note that byteData.position has changed to the end of the stream.

    // ... do stuff ...

    free(byteArray_c);
}
于 2016-06-12T02:55:51.263 に答える