守望者--AIR技术交流

标题: 传递ByteArray参数到C++里 [打印本页]

作者: 破晓    时间: 2015-3-11 09:24
标题: 传递ByteArray参数到C++里
  1. void _init_c(void) __attribute((used,
  2.     annotate("as3sig:public function init(byteData:ByteArray) : void"),
  3.     annotate("as3import:flash.utils.ByteArray")));

  4. void _init_c()
  5. {
  6.     char *byteArray_c;
  7.     unsigned int len;

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

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

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

  14.     // ... do stuff ...

  15.     free(byteArray_c);
  16. }
复制代码

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





欢迎光临 守望者--AIR技术交流 (http://www.airmyth.com/)