C/C++ API Reference
AS3.h
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 Crossbridge documentation for examples of how you can use GCC's inline asm syntax for interoperating between C/C++ and AS3. Parameters:
Example Usage: See the 02_Interop sample (hellointerop.c) |
inline_nonreentrant_as3 |
If your AS3 code doesn't re-enter Crossbridge code you can use this. But if it does re-enter Crossbridge 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:
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:
Example Usage: See the Example_Lua sample |
AS3_GoAsync |
When breaking a C/C++ run-loop so that Crossbridge 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: See the 04_Animation sample |
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 |
Returns an AS3 variable via an AS3 return. 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 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:
Parameters:
Example Usage: #include <AS3/AS3.h> int main() { AS3_Trace("Hello World!"); } |
AS3_MallocString |
Marshalls an AS3 string into a C char*. This will call malloc behind the scenes so you must free it later. Parameters:
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 } Also see the 05_SWC sample |
AS3_StringLength |
Sets the value of CVAR to the length of the ActionScript string STR. Parameters:
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 } Also see the 05_SWC sample |
AS3_DeclareVar |
Declares an AS3 variable in the current function. Parameters:
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 |
Marshalls a C character string into a local AS3 string variable. Parameters:
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 |
Marshalls a C character into a local AS3 string variable. Parameters:
Example Usage: #include <AS3/AS3.h> int main() { char* ch = "A"; |
AS3_CopyScalarToVar |
Copies a scalar C value into a local AS3 variable. Parameters:
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 |
Copies an AS3 local variable into a local C variable. Parameters:
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 |
Copies an AS3 local variable into an AS3::local::var C++ variable. Parameters:
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 |
Copies an AS3::local::var C++ variable into an AS3 local variable. Parameters:
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 |
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:
Example Usage: #include <AS3/AS3.h> int main() { char* status = "success"; AS3_SendMetricString("my.metric.complete", status); } |
AS3_SendMetricInt |
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:
Example Usage: #include <AS3/AS3.h> int main() { int result = 5; AS3_SendMetricInt("my.metric.complete", result); } Also see the Example_Quake sample |