gpt4 book ai didi

actionscript - 如何使用 FlasCC 将 ByteArray 传递给 C 代码

转载 作者:行者123 更新时间:2023-12-04 04:58:26 25 4
gpt4 key购买 nike

我想将 ByteArray 从 ActionScript 传递给 C 函数。

基本上我想做这样的事情:

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 文档中找不到任何功能来帮助我解决这个问题。

最佳答案

例子:

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中的堆在AS3端暴露为CModule.ram,这是一个ByteArray对象。

在 C 中 malloc 的指针在 AS3 中被视为 CModule.ram 的偏移量。

关于actionscript - 如何使用 FlasCC 将 ByteArray 传递给 C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14326828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com