[待测试特性]
一、C接口导出相关
1、重载函数。
2、虚函数。
3、template相关
二、内存相关
1、as直接往c分配的内存写数据。
2、c直接往as对象写数据。
三、C访问AS
1、访问as中的基本类型变量
2、访问as中的复杂类型变量
3、访问as中的function对象
4、inline assembly. 官方文档说明如下:
The interop between AS3 and C/C++ in FlasCC is based around the concept of inline assembly. In a native C/C++ workflow you would use inline assembly statements to allow you to pass arbitrary strings containing platform specific instructions to the assembler to be included in your final executable. With FlasCC the underlying system is the Flash Runtime, and the language it supports natively is AS3, so these inline assembly statements let you talk to the native Flash API set in the language it was designed with.
其中有两种常用的macro, inline_as3
和 package_as3
。用法如下:
#include <AS3/AS3.h> // Use AS3 to sqrt a double! double somenumber = 45.0; double result = 0.0; inline_as3( "%0 = Math.sqrt(%1); " : "=r"(result) : "r"(somenumber) ); // Back in C we can take the result and print it out: printf("sqrt of %f is %f ", somenumber, result);
package_as3("#package public var somepublicvar:int = 42;"); package_as3("#package private var someprivatevar:int = 42;"); package_as3("#package com.example.yourpackage var somespecialvar:int = 42;");
四、AS访问C
五、多线程(pthread与worker)
adobe官方对于pthread的说明:
http://www.adobe.com/devnet/games/articles/pthreads-flascc.html
其中有一段话很重要:
Flascc Pthreads are implemented using ActionScript workers. Creation of a Pthread causes the creation of an AS3 Worker object on which the Pthread start_routine
runs. Workers created for Pthread execution automatically share C memory with other Pthreads including the main Pthread. Global and static variables are shared between Pthreads. Therefore, C data—including pointers to scalars, function pointers, and so on—can be safely shared between Pthreads. However, AS3 values are not shared between workers and therefore are not generally shareable between Pthreads.
六、flascc中比较难理解的接口和系统概念
1、flascc模块的初始化入口
和c程序类似, 一个flascc模块建议使用一个main函数作为其入口。
AS3_GoAsync宏
When breaking a C/C++ run-loop so that FlasCC code is suitable for use without using multi-threading you need to execute main, so the static initializers for your code are run, but you want to prevent the static destructors from running so it is important that main does not return. By throwing an AS3 exception and preserving the stack we can effectively interrupt the execution of main.
2、as中对于flascc模块的加载
要使用一个flascc编写的模块swc, 在使用之前要对其进行加载, 也就是初始化, 这个要利用CModule来操作。 对于CModule要说明的是, 每一个flascc模块swc都有一个唯一对应的CModule类, 利用这个类可以对与之对应的swc进行操作,比如初始化, 读写内存等。
七、系统模块说明
1、CModule
1.1 初始化接口
1.1.1 start()
Calls the libc __start1
function which, in turn, causes main()
to execute.
1.1.2 startAsync()
Calls the libc __start1
function which, in turn, causes main()
to execute. Unlike start()
, this method handles the case where the main C run loop has been broken by a call to "AS3_GoAsync" within the C code. This allows main to return without allowing C/C++ static initializers to run. This should be used when you want to run long running code with a broken run-loop, or run some code as a library.
1.1.3 startBackground()
Creates a background Worker and runs the libc function __start1
within that Worker. This allows you to run main without breaking the run loop, but requires the SWF to be version 18 or higher (Flash Runtime 11.5).
这三个接口的参数一致, 如下:
Parameters
console:Object (default = null) — The current Console object
args:Vector.<String> (default = null) — A vector of Strings that are used to fill the argv array given to main. The first String is typically used to specify the name of the application.
env:Vector.<String> (default = null) — A vector of Strings that are used to populate the environment variables accesible by getenv(). There should be an even number of Strings in this Vector as they are treated as name/value pairs.
afterStackSize:int (default = 65536) — The amount of stack space to allocate for the ui thread (code that will run the uiThunk callbacks and also any calls to callI coming from the main Worker).
1.2 property
1.2.1 rootSprite
如果仅仅是在一个单线程里加载并使用flascc模块, 随便new sprite给这个属性就好。
奇怪的是,如果在flascc模块里用到pthread创建另外一个线程, 如果rootSprite的loadInfo为空的话, 就会报错。这就意味着必须用根sprite或者一个动态加载的swf才能赋给这个属性。
2、Console
3、IVFS
4、ISpecialFile
5、IKernel