Flash通过Action Script调用C++接口
2012-05-03 10:43
405 查看
适用场景:比如游戏逻辑部分用C++编写,而界面UI则采用flash,程序移植也很方便。
为什么用Adobe Alchemy,Adobe Alchemy有什么优势?
了解 flash AS3 与 C++的异同
Alchemy C/C++ API
安装使用Adobe Alchemy
即使没有返回值,不需要传入参数,接口形式也如上,否则不能成功注册。
当编译时出现如下提示,很多情况下貌似可以忽略。
For example, right before you called AS3_Function, you could have set up some struct or whatever in C, passed that as the data argument, and then you can use that inside of the function that you pass as well.
When you call AS3_Function, you're just setting up a function that can be called by ActionScript later. However, you might want to have some context to that call, and you're allowed to pass that context as data in the first argument.
Declaring a parameter as the void pointer type is kind of like the any type (*) in AS3, in that it signifies that the data can be of any type. In C, though, you will almost invariably cast the value to a known type so you can access fields from it, like: ((SomeType*) data)->someFunction().
From ActionScript, yes, but what happens behind the scenes is a bit different. Your C function will be called with that data pointer that you pass to AS3_Function when you created the callback.
This whole thing is just an Alchemy convention, though, it doesn't really have a lot to do with C.
详见http://www.kirupa.com/forum/showthread.php?356452-C-parameter-doubt
为什么用Adobe Alchemy,Adobe Alchemy有什么优势?
了解 flash AS3 与 C++的异同
Alchemy C/C++ API
安装使用Adobe Alchemy
// 接口编写形式: #include "AS3.h" AS3_Val func(void* self, AS3_Val args); // ...
即使没有返回值,不需要传入参数,接口形式也如上,否则不能成功注册。
当编译时出现如下提示,很多情况下貌似可以忽略。
For example, right before you called AS3_Function, you could have set up some struct or whatever in C, passed that as the data argument, and then you can use that inside of the function that you pass as well.
When you call AS3_Function, you're just setting up a function that can be called by ActionScript later. However, you might want to have some context to that call, and you're allowed to pass that context as data in the first argument.
Declaring a parameter as the void pointer type is kind of like the any type (*) in AS3, in that it signifies that the data can be of any type. In C, though, you will almost invariably cast the value to a known type so you can access fields from it, like: ((SomeType*) data)->someFunction().
From ActionScript, yes, but what happens behind the scenes is a bit different. Your C function will be called with that data pointer that you pass to AS3_Function when you created the callback.
This whole thing is just an Alchemy convention, though, it doesn't really have a lot to do with C.
详见http://www.kirupa.com/forum/showthread.php?356452-C-parameter-doubt
相关文章推荐
- AS通过Cmake JNI方式调用OpenCV C++接口和调用OpenCV Java接口混合开发基础
- C/C++通过gSoap发布webservice接口,供ASP.Net网站工程调用
- C++通过gsoap做WebService接口 供C++及java客户端调用
- 通过JNI实现Java和C++的相互调用(转)
- AndroidJNI 通过C++调用JAVA
- C++调用Cimiss接口返回值
- 通过接口调用方法,接口一直为null的解决方法
- Cocos2d-x中通过JNI进行C++调用Java代码
- python下面通过ctypes模块调用c++库的方法
- C++通过DLL调用C#代码
- Java通过JNI调用C++的DLL库
- VS2010中c++程序调用PostgreSQL数据库C接口libpq.lib的项目Properties设置
- cocos2d-x 中多线程的c/c++代码通过JNI调用java代码
- (原)python使用ctypes调用C/C++接口
- C调用C++接口
- AndroidJNI 通过C++调用JAVA
- java通过url调用远程接口返回json数据,有用户名和密码验证
- C++通过Webbrowser调用JavaScript
- 在Electron中通过ffi模块实现JavaScript调用C++动态库
- Java通过JNI调用C++程序