- 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);
- }
复制代码
The key here is that the heap in C is exposed on the AS3 side as CModule.ram, which is a ByteArrayobject. A pointer malloc'd in C is seen in AS3 as an offset into CModule.ram.
可以参考例子中的 /06_SWIG/ PassingData/ PassData.as
相关链接:
http://stackoverflow.com/questio ... c-code-using-flascc
|