守望者--AIR技术交流

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: ANE FlasCC 炼金术
查看: 3215|回复: 0

[技术知识] 传递ByteArray参数到C++里

[复制链接]
  • TA的每日心情
    擦汗
    2018-4-10 15:18
  • 签到天数: 447 天

    [LV.9]以坛为家II

    1742

    主题

    2094

    帖子

    13万

    积分

    超级版主

    Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

    威望
    562
    贡献
    29
    金币
    52680
    钢镚
    1422

    开源英雄守望者

    发表于 2015-3-11 09:24:43 | 显示全部楼层 |阅读模式
    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技术交流社区(www.airmyth.com)
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    
    关闭

    站长推荐上一条 /4 下一条

    QQ|手机版|Archiver|网站地图|小黑屋|守望者 ( 京ICP备14061876号

    GMT+8, 2024-4-16 13:48 , Processed in 0.044323 second(s), 31 queries .

    守望者AIR

    守望者AIR技术交流社区

    本站成立于 2014年12月31日

    快速回复 返回顶部 返回列表