我想把ActionScript中的ByteArray传递给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文档中找不到任何函数来帮助我做到这一点。
发布于 2013-02-21 07:33:18
示例:
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中被恶意锁定的指针在AS3中被视为到CModule.ram的偏移量。
发布于 2013-01-27 18:39:13
您应该使用CModule.malloc和CModule.writeBytes方法以C风格的方式操作指针。看一看$FLASCC/samples/06_SWIG/PassingData/PassData.as
发布于 2016-06-12 10:55:51
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);
}https://stackoverflow.com/questions/14326828
复制相似问题