Flex Alchemy:从 C 函数返回 ByteArray

发布于 2024-08-08 23:12:33 字数 209 浏览 13 评论 0 原文

我正在使用 Flex 的 Alchemy 库从 C 文件生成 SWC。我在 c 层中有一个字节数组 (unsigned char buffer[size]),我想将其作为 ByteArray 返回到 ActionScript 层。我是否必须迭代数组并在每个元素上显式调用 AS3_Set 或者是否有办法立即返回整个 C 数组?

I am using Flex's Alchemy library to generate SWC's out of C files. I have a byte array (unsigned char buffer[size]) in the c-layer that I'd like to return to the ActionScript layer as a ByteArray. Do I have to iterate through the array and explicitly call AS3_Set on each element or is there a way to just return the entire C array at once?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耳钉梦 2024-08-15 23:12:33

这可以通过使用 AS3_ByteArray_writeBytes 函数。

This can be accomplished by using the AS3_ByteArray_writeBytes function of the Alchemy API.

忆沫 2024-08-15 23:12:33

在 C 中,当从 Flash 调用的函数返回时,返回指向 C 数组的指针,如下所示:

int * myArray = malloc(100);
//populate array...
return AS3_Array("IntType", (int)myArray);

然后,在 Flash 中:

import cmodule.<c module name>.MemUser;
...
memory = new MemUser();
for (var i:int = 0; i<4;i++) { //getting a 4 uints array
    trace(memory._mru16(data[0] + i*4)); //data is the return value from C
}

或者使用 这些函数从c数组中读取ints/floats/char(你不能只使用ByteArray.readInt(),c中的数字表示方式不同)

In C, when returning from the function called by Flash, return the pointer to the C-array, like this:

int * myArray = malloc(100);
//populate array...
return AS3_Array("IntType", (int)myArray);

Then, in Flash:

import cmodule.<c module name>.MemUser;
...
memory = new MemUser();
for (var i:int = 0; i<4;i++) { //getting a 4 uints array
    trace(memory._mru16(data[0] + i*4)); //data is the return value from C
}

Or use these functions to read the ints/floats/char from the c-array (you can't just use ByteArray.readInt(), the numbers in c are represented differently)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文