Use the macros in the AS3.h header file to inject ActionScript 3 code into your C/C++ code.
Function | Description |
inline_as3
| The inline_as3 macro correctly restores the global stack pointer and lets you inject arbitrary AS3 code within the body of a C/C++ function. Refer to the FlasCC documentation for examples of how you can use GCC's inline asm syntax for interoperating between C/C++ and AS3. Parameters: - ... - Arbitrary ActionScript code including inline asm.
Example Usage: |
inline_nonreentrant_as3
| - #define inline_nonreentrant_as3(...)
复制代码If your AS3 code doesn't re-enter FlasCC code you can use this. But if it does re-enter FlasCC code (either directly or indirectly via something like CModule.mallocString) then your stack will be smashed. Use inline_as3 unless you are really sure this is what you want! Parameters: - ... - Arbitrary ActionScript code including inline asm.
Example Usage: See the Example_Lua sample |
package_as3
| The package_as3 macro lets you inject arbitrary AS3 into the module namespace associated with the current C/C++ translation unit. This is useful for declaring global AS3 variables that you want to reference from inline as3 asm statements within C/C++ functions. Parameters: - ... - Arbitrary ActionScript code including inline asm.
Example Usage: See the Example_Lua sample |
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. Example Usage: |
AS3_Return
| Returns a value via an AS3 return. Must be a scalar value. Parameters: Example Usage: The code in this example is designed to be compiled into a SWC. See the 05_SWC sample to learn how to compile and run this example. - #include <stdlib.h>
- #include "AS3/AS3.h"
- void returnPi() __attribute__((used,
- annotate("as3sig:public function returnPi():Number"),
- annotate("as3package:MyLibrary")));
- void returnPi(){
- float pi = 3.14159;
- AS3_Return(pi);
- }
- int main(){
- // See the code comments in samples/05_SWC for more details.
- AS3_GoAsync();
- }
复制代码 |
AS3_ReturnAS3Var
| - #define AS3_ReturnAS3Var(AS3VAR)
复制代码Returns an AS3 variable via an AS3 return. Parameters: - AS3VAR - An AS3 variable.
Example Usage: The code in this example is designed to be compiled into a SWC. See the 05_SWC sample to learn how to compile and run this example. - #include <stdlib.h>
- #include "AS3/AS3.h"
- void returnString() __attribute__((used,
- annotate("as3sig:public function returnString():String"),
- annotate("as3package:MyLibrary")));
- void returnString(){
- char* s = "Hello World";
-
- // We can't just call AS3_Return(s) because s is not a scalar.
- // Instead we need to marshall the C string into AS3 and use
- // AS3_ReturnAS3Var().
-
- AS3_DeclareVar(myString, String);
- AS3_CopyCStringToVar(myString, s, 11);
- AS3_ReturnAS3Var(myString);
- }
- int main(){
- // See samples/05_SWC for more details.
- AS3_GoAsync();
- }
复制代码 |
AS3_Trace
| Simple wrapper to trace strings to the flash log file, which can be found in one of these locations: - Windows 95/98/ME/2000/XP - C:\Documents and Settings\username\Application Data\Macromedia\Flash Player\Logs
- Windows Vista/Windows 7 - C:\Users\username\AppData\Roaming\Macromedia\Flash Player\Logs
- Macintosh OS X - /Users/username/Library/Preferences/Macromedia/Flash Player/Logs/
- Linux - /home/username/.macromedia/Flash_Player/Logs/
Parameters: Example Usage: - #include <AS3/AS3.h>
- int main() {
- AS3_Trace("Hello World!");
- }
复制代码 |
AS3_MallocString
| - #define AS3_MallocString(CVAR, STR)
复制代码Marshalls an AS3 string into a C char*. This will call malloc behind the scenes so you must free it later. Parameters: - CVAR - A variable in C.
- STR - An ActionScript string.
Example Usage: - #include <AS3/AS3.h>
- #include <stdio.h>
- int main() {
- inline_as3("var myString:String = 'hello';\n");
-
- char *str = NULL;
- AS3_MallocString(str, myString);
-
- printf("str=%s", str); // output: str=hello
- free(str); // remember to free
- }
复制代码
|
AS3_StringLength
| - #define AS3_StringLength(CVAR, STR)
复制代码Sets the value of CVAR to the length of the ActionScript string STR. Parameters: - CVAR - A variable in C.
- STR - A string or an ActionScript variable.
Example Usage: - #include <AS3/AS3.h>
- #include <stdio.h>
- int main() {
- inline_as3("var myString:String = 'hello';\n");
-
- int strLen = 0;
-
- AS3_StringLength(strLen, myString);
- printf("strLen=%d\n", strLen); // output: 5
-
- AS3_StringLength(strLen, "hello world");
- printf("strLen=%d\n", strLen); // output: 11
- }
复制代码 |
AS3_DeclareVar
| - #define AS3_DeclareVar(AS3NAME, AS3TYPE)
复制代码Declares an AS3 variable in the current function. Parameters: - AS3NAME - Name of the ActionScript variable to declare.
- AS3TYPE - Type of the ActionScript variable to declare (ex: String).
Example Usage: - #include <AS3/AS3.h>
- int main() {
- int x = 5;
- // declare an ActionScript variable of type Number
- AS3_DeclareVar(myAS3Number, Number);
- // assign a value to that variable
- AS3_CopyScalarToVar(myAS3Number, x);
- // trace the value
- AS3_Trace("myAS3Number=" + myAS3Number);
- }
复制代码Also see the Example_Lua sample |
AS3_CopyCStringToVar
| - #define AS3_CopyCStringToVar(AS3VAR, CSTRPTR, LEN)
复制代码Marshalls a C character string into a local AS3 string variable. Parameters: - AS3VAR - ActionScript variable to assign the string value to.
- CSTRPTR - Pointer to the C character string.
- LEN - Length of the C character string.
Example Usage: - #include <AS3/AS3.h>
- int main() {
- char* str = "hello";
-
- AS3_DeclareVar(myString, String);
- AS3_CopyCStringToVar(myString, str, 5);
- AS3_Trace("myString=" + myString);
- }
复制代码Also see the Example_Lua sample |
AS3_CopyCharToVar
| - #define AS3_CopyCharToVar(AS3VAR, CSTRPTR)
复制代码Marshalls a C character into a local AS3 string variable. Parameters: - AS3VAR - ActionScript variable to assign the character value to.
- CSTRPTR - Pointer to the C character.
Example Usage: - #include <AS3/AS3.h>
- int main() {
- char* ch = "A";
-
- AS3_DeclareVar(myString, String);
- AS3_CopyCharToVar(myString, ch);
- AS3_Trace("myString=" + myString);
- }
复制代码 |
AS3_CopyScalarToVar
| - #define AS3_CopyScalarToVar(AS3VAR, VAL)
复制代码Copies a scalar C value into a local AS3 variable. Parameters: - AS3VAR - ActionScript variable to assign the scalar to.
- VAL - A scalar value (ex: int, double, boolean).
Example Usage: - #include <AS3/AS3.h>
- int main() {
- int x = 5;
- // declare an ActionScript variable of type Number
- AS3_DeclareVar(myAS3Number, Number);
- // assign a value to that variable
- AS3_CopyScalarToVar(myAS3Number, x);
- // trace the value
- AS3_Trace("myAS3Number=" + myAS3Number);
- }
复制代码 |
AS3_GetScalarFromVar
| - #define AS3_GetScalarFromVar(CVAR, AS3VAR)
复制代码Copies an AS3 local variable into a local C variable. Parameters: - CVAR - A C variable to copy the value into.
- AS3VAR - ActionScript variable.
Example Usage: - #include <AS3/AS3.h>
- #include <stdio.h>
- int main() {
- inline_as3("var myAS3Number:Number = 5");
- int x;
- AS3_GetScalarFromVar(x, myAS3Number);
- printf("x=%d\n", x); // output: x=5
- }
复制代码 |
AS3_GetVarxxFromVar
| - #define AS3_GetVarxxFromVar(CVARXX, AS3VAR)
复制代码Parameters: - CVARXX - An AS3::local::var object.
- AS3VAR - ActionScript variable.
Example Usage: - #include <AS3/AS3.h>
- #include <AS3/AS3++.h>
- int main() {
- inline_as3("var myString = 'hello';");
-
- AS3::local::var cVar;
- AS3_GetVarxxFromVar(cVar, myString);
-
- char* str = AS3::local::internal::utf8_toString(cVar);
- printf("cVar=%s\n", str); // output: cVar=hello
- free(str);
- }
复制代码 |
AS3_CopyVarxxToVar
| - #define AS3_CopyVarxxToVar(AS3VAR, CVARXX)
复制代码Parameters: - AS3VAR - ActionScript variable.
- CVARXX - An AS3::local::var object.
Example Usage: - #include <AS3/AS3.h>
- #include <AS3/AS3++.h>
- int main() {
- inline_as3("var myString:String = 'hello';");
- AS3_Trace(myString); // output: hello
-
- AS3::local::var cVar = AS3::local::internal::new_String("world");
- AS3_CopyVarxxToVar(myString, cVar);
- AS3_Trace(myString); // output: world
- }
复制代码 |
AS3_SendMetricString
| - void AS3_SendMetricString(const char* metric, const char *value);
复制代码Sends a metric to Adobe Scout with a string value. The metric will show up in the metric summary panel for the frame it was sent in. Parameters: - metric - C character string representing the metric name.
- value - C character string representing the metric value.
Example Usage: - #include <AS3/AS3.h>
- int main() {
- char* status = "success";
- AS3_SendMetricString("my.metric.complete", status);
- }
复制代码 |
AS3_SendMetricInt
| - void AS3_SendMetricInt(const char* metric, int value);
复制代码Sends a metric to Adobe Scout with an integer value. The metric will show up in the metric summary panel for the frame it was sent in. Parameters: - metric - C character string representing the metric name.
- value - An integer value.
Example Usage: - #include <AS3/AS3.h>
- int main() {
- int result = 5;
- AS3_SendMetricInt("my.metric.complete", result);
- }
复制代码Also see the Example_Quake sample |