Packagecom.adobe.flascc
Classpublic class CModule
InheritanceCModule Inheritance Object

Contains convenience functions for reading and writting to domainMemory; also manages any flascc-specific global state (for example, the VFS and Posix interface implementations.)



Public Properties
 PropertyDefined By
  activeConsole : Object
[static] A reference to the current Console object, it is set when one of the start methods is called
CModule
  canUseWorkers : Boolean
[static] [read-only] Returns true if the current environment supports use of ActionScript Workers with flascc content
CModule
  kernel : IKernel
[static] Return the current kernel implementation
CModule
  ram : ByteArray
[static] [read-only] Returns the ByteArray object using as RAM
CModule
  rootSprite : Sprite
[static] A reference to the current rootSprite so that flascc code has an easy way of getting to the stage regardless of what preloaders might be employed.
CModule
  throwWhenOutOfMemory : Boolean
[static] Returns a boolean indicating whether Flash out of memory conditions when growing the domainMemory ByteArray will throw an ActionScript exception.
CModule
  vfs : IVFS
[static] The current VFS implementation
CModule
Public Methods
 MethodDefined By
  
allocaLatin1String(s:String):int
[static] Allocas a Latin1 String
CModule
  
allocaString(s:String):int
[static] TBD
CModule
  
callI(functionPtr:int, args:Vector.<int> = null, stack:int = 0, preserveStack:Boolean = false):int
[static] Low level API for calling a C/C++ function from Actionscript, returning a 32-bit value
CModule
  
callN(functionPtr:int, args:Vector.<int> = null, stack:int = 0, preserveStack:Boolean = false):Number
[static] Low level API for calling a C/C++ function from Actionscript returning a 64-bit floating point value
CModule
  
dispose():void
Resets the object properties and frees memory.
CModule
  
free(ptr:int):void
[static] Free a pointer that was previously allocated using CModule.malloc().
CModule
  
getPublicSymbol(name:String):int
[static] Lookup the specified publicly defined C/C++ symbol
CModule
  
malloc(size:int):int
[static] Allocate size bytes of data within the domainMemory ByteArray.
CModule
  
mallocLatin1String(s:String):int
[static] Mallocs a Latin1 String
CModule
  
mallocString(s:String):int
[static] Allocate a buffer in domainMemory and write an actionscript string as UTF8 data into that buffer.
CModule
  
read16(ptr:int):int
[static] Read a 16 bit value from domainMemory with zero padding to extend it to a 32 bit signed integer.
CModule
  
read32(ptr:int):int
[static] Read a 32 bit value from domainMemory.
CModule
  
read8(ptr:int):int
[static] Read an 8 bit value from domainMemory with zero padding to extend it to a 32 bit signed integer.
CModule
  
readBytes(ptr:int, length:uint, dst:IDataOutput):void
[static] Copy data from domainMemory into an object implementing the IDataOutput interface (ByteArray, FileStream, Socket etc)
CModule
  
readDouble(ptr:int):Number
[static] Read a 64 bit floating point value from domainMemory
CModule
  
readFloat(ptr:int):Number
[static] Read a 32 bit floating point value from domainMemory
CModule
  
readIntVector(ptr:int, count:int):Vector.<int>
[static] Read count integers from the offset ptr in domainMemory into a Vector of ints.
CModule
  
readString(ptr:int, length:int):String
[static] Read UTF8 data from domainMemory and construct an Actionscript String
CModule
  
regFun(ptr:int, f:Function):void
[static] Registers a function by pointer
CModule
  
runningAsWorker():Boolean
[static] Console should use this function to check if the SWF has been launched as an isolate so it can act appropriately
CModule
  
serviceUIRequests(event:Object = null):void
[static] This method services any pending uiThunk requests that background threads have queued up.
CModule
  
start(console:Object, args:Vector.<String> = null, env:Vector.<String> = null, preserveStack:Boolean = true):int
[static] Calls the libc __start1 function which, in turn, causes main() to execute.
CModule
  
startAsync(console:Object = null, args:Vector.<String> = null, env:Vector.<String> = null, preserveStack:Boolean = true, isAutoSetRealThreadId:Boolean = true):void
[static] Calls the libc __start1 function which, in turn, causes main() to execute.
CModule
  
startBackground(console:Object = null, args:Vector.<String> = null, env:Vector.<String> = null, afterStackSize:int = 65536):void
[static] Creates a background Worker and runs the libc function __start1 within that Worker.
CModule
  
write16(ptr:int, value:int):void
[static] Write the low 16 bits of value into domainMemory.
CModule
  
write32(ptr:int, value:int):void
[static] Write a 32 bit value into domainMemory
CModule
  
write8(ptr:int, value:int):void
[static] Write the low 8 bits of value into domainMemory.
CModule
  
writeBytes(ptr:int, length:uint, source:IDataInput):void
[static] Copy the contents of an object that implements the IDataInput interface (ByteArray, FileStream, Socket etc) into domainMemory.
CModule
  
writeDouble(ptr:int, value:Number):void
[static] Write a Number as a 64 bit float into domainMemory
CModule
  
writeFloat(ptr:int, value:Number):void
[static] Write a Number as a 32 bit float into domainMemory
CModule
  
writeIntVector(ptr:int, vec:Vector.<int>):void
[static] Write a Vector of ints into domainMemory starting at offset ptr.
CModule
  
writeString(ptr:int, s:String):int
[static] Write an actionscript string as UTF8 data into domainMemory
CModule
Property Detail
activeConsoleproperty
public static var activeConsole:Object

A reference to the current Console object, it is set when one of the start methods is called

canUseWorkersproperty 
canUseWorkers:Boolean  [read-only]

Returns true if the current environment supports use of ActionScript Workers with flascc content


Implementation
    public static function get canUseWorkers():Boolean
kernelproperty 
kernel:IKernel

Return the current kernel implementation


Implementation
    public static function get kernel():IKernel
    public static function set kernel(value:IKernel):void
ramproperty 
ram:ByteArray  [read-only]

Returns the ByteArray object using as RAM


Implementation
    public static function get ram():ByteArray
rootSpriteproperty 
public static var rootSprite:Sprite

A reference to the current rootSprite so that flascc code has an easy way of getting to the stage regardless of what preloaders might be employed.

throwWhenOutOfMemoryproperty 
throwWhenOutOfMemory:Boolean

Returns a boolean indicating whether Flash out of memory conditions when growing the domainMemory ByteArray will throw an ActionScript exception. The default is false, malloc will return an appropriate failure and new/new[] will throw a std::badalloc C++ exception.


Implementation
    public static function get throwWhenOutOfMemory():Boolean
    public static function set throwWhenOutOfMemory(value:Boolean):void
vfsproperty 
vfs:IVFS

The current VFS implementation


Implementation
    public static function get vfs():IVFS
    public static function set vfs(value:IVFS):void
Method Detail
allocaLatin1String()method
public static function allocaLatin1String(s:String):int

Allocas a Latin1 String

Parameters

s:String

Returns
int
allocaString()method 
public static function allocaString(s:String):int

TBD

Parameters

s:String

Returns
int
callI()method 
public static function callI(functionPtr:int, args:Vector.<int> = null, stack:int = 0, preserveStack:Boolean = false):int

Low level API for calling a C/C++ function from Actionscript, returning a 32-bit value

Parameters

functionPtr:int — The address of the function. You can find the address of a C/C++ function by passing the name of the function to getPublicSym.
 
args:Vector.<int> (default = null) — An optional vector containing 32-bit values to pass on the stack to the function. These could either be primitive integer data, or pointers. To pass more complex data types (including AS3 types) you should use the function annotation syntax explained in the interop tutorial to give the function a more natural AS3 function signature.
 
stack:int (default = 0) — An optional pointer to the base of the stack. A value of 0 means use the current ESP.
 
preserveStack:Boolean (default = false) — Indicates whether the stack pointer should unwind back to the value it was before the function was called.

Returns
int — The integer return value of the function. As above, to return complex (possibly AS3) types you should annotate the function as explained in the interop tutorial to give the function a more natural signature and return type.
callN()method 
public static function callN(functionPtr:int, args:Vector.<int> = null, stack:int = 0, preserveStack:Boolean = false):Number

Low level API for calling a C/C++ function from Actionscript returning a 64-bit floating point value

Parameters

functionPtr:int — The address of the function. You can find the address of a C/C++ function by passing the name of the function to getPublicSym.
 
args:Vector.<int> (default = null) — A Vector containing 32-bit values to pass on the stack to the function. These could ewither be primitive integer data, or pointers. To pass more complex data types (including AS3 types) you should use the function annotation syntax explained in the interop tutorial to give the function a mopre natural AS3 function signature.
 
stack:int (default = 0) — An optional pointer to the base of the stack. A value of 0 means use the current ESP.
 
preserveStack:Boolean (default = false) — Indicates whether the stack pointer should unwind back to the value it was before the function was called.

Returns
Number — The 64-bit floating point return value of the function. As above, to return complex (possibly AS3) types you should annotate the function as explained in the interop tutorial to give the function a more natural signature and return type.
dispose()method 
public function dispose():void

Resets the object properties and frees memory.

free()method 
public static function free(ptr:int):void

Free a pointer that was previously allocated using CModule.malloc(). Internally this calls the libc implementation of free() so it can be used to free pointers allocated in C with malloc().

Parameters

ptr:int

getPublicSymbol()method 
public static function getPublicSymbol(name:String):int

Lookup the specified publicly defined C/C++ symbol

Parameters

name:String — The name of the symbol to lookup, for example, "malloc"

Returns
int — The address of the symbol. If the symbol was a POD type you can read it's value using one of the read functions. If the symbol was a function then you can call it using callI.
malloc()method 
public static function malloc(size:int):int

Allocate size bytes of data within the domainMemory ByteArray. The memory must be freed using CModule.free().

Parameters

size:int

Returns
int — A pointer to a region of memory within domainMemory size bytes long. Internally this calls the libc implementation of malloc() so the returned value should be treated as though it had been allocated in C with malloc().
mallocLatin1String()method 
public static function mallocLatin1String(s:String):int

Mallocs a Latin1 String

Parameters

s:String

Returns
int
mallocString()method 
public static function mallocString(s:String):int

Allocate a buffer in domainMemory and write an actionscript string as UTF8 data into that buffer.

Parameters

s:String — The string you want to copy into domainMemory

Returns
int — The pointer to the buffer in domainMemory that contains the string. This must be manually freed by passing this pointer to "free()"
read16()method 
public static function read16(ptr:int):int

Read a 16 bit value from domainMemory with zero padding to extend it to a 32 bit signed integer. This will always result in positive integers.

Parameters

ptr:int — The address of the location in domainMemory to read from

Returns
int — A 16 bit integer zero padded to 32 bit.
read32()method 
public static function read32(ptr:int):int

Read a 32 bit value from domainMemory.

Parameters

ptr:int — The address of the location in domainMemory to read from

Returns
int — A 32 bit integer.
read8()method 
public static function read8(ptr:int):int

Read an 8 bit value from domainMemory with zero padding to extend it to a 32 bit signed integer. This will always result in positive integers.

Parameters

ptr:int — The address of the location in domainMemory to read from

Returns
int — An 8 bit integer zero padded to 32 bit.
readBytes()method 
public static function readBytes(ptr:int, length:uint, dst:IDataOutput):void

Copy data from domainMemory into an object implementing the IDataOutput interface (ByteArray, FileStream, Socket etc)

Parameters

ptr:int — The address of the location in domainMemory to start reading from.
 
length:uint — The number of bytes to copy from the domainMemory (starting from ptr)
 
dst:IDataOutput — The IDataOutput to copy data into (the current position in this IDataOutput will be respected and will increase by length)

readDouble()method 
public static function readDouble(ptr:int):Number

Read a 64 bit floating point value from domainMemory

Parameters

ptr:int — The address of the location in domainMemory to read from

Returns
Number — A signed 64 bit floating point value
readFloat()method 
public static function readFloat(ptr:int):Number

Read a 32 bit floating point value from domainMemory

Parameters

ptr:int — The address of the location in domainMemory to read from

Returns
Number — A signed 32 bit floating point value
readIntVector()method 
public static function readIntVector(ptr:int, count:int):Vector.<int>

Read count integers from the offset ptr in domainMemory into a Vector of ints.

Parameters

ptr:int — The offset in domainMemory to read from
 
count:int — The number of 32 bit integers to read

Returns
Vector.<int> — A Vector of ints read from domainMemory
readString()method 
public static function readString(ptr:int, length:int):String

Read UTF8 data from domainMemory and construct an Actionscript String

Parameters

ptr:int — The location in domainMemory to start reading from
 
length:int — The number of bytes to read

Returns
String — A String constructed from the UTF8 data found between ptr and ptr+length
regFun()method 
public static function regFun(ptr:int, f:Function):void

Registers a function by pointer

Parameters

ptr:int
 
f:Function

runningAsWorker()method 
public static function runningAsWorker():Boolean

Console should use this function to check if the SWF has been launched as an isolate so it can act appropriately

Returns
Boolean
serviceUIRequests()method 
public static function serviceUIRequests(event:Object = null):void

This method services any pending uiThunk requests that background threads have queued up. A good place to call this would be in the enterFrame handler. Update: you can attach your dispatchers directly into this handler since the optional event arg.

Parameters

event:Object (default = null)

start()method 
public static function start(console:Object, args:Vector.<String> = null, env:Vector.<String> = null, preserveStack:Boolean = true):int

Calls the libc __start1 function which, in turn, causes main() to execute.

Parameters

console:Object — 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.
 
preserveStack:Boolean (default = true) — Indicates whether the C stack should be preserved after the call to __start1. If this is set to false the stack depth will return to the value when start() was called upon return.

Returns
int — The exit code of the C application
startAsync()method 
public static function startAsync(console:Object = null, args:Vector.<String> = null, env:Vector.<String> = null, preserveStack:Boolean = true, isAutoSetRealThreadId:Boolean = true):void

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.

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.
 
preserveStack:Boolean (default = true) — Inidcates whether the C stack should be preserved after the call to __start1. If this is set to false the stack depth will return to the value when start() was called upon return.
 
isAutoSetRealThreadId:Boolean (default = true) — Inidcates whether the module should auto-set its real thread id. Use false when using multi-threaded SWCs.

startBackground()method 
public static function startBackground(console:Object = null, args:Vector.<String> = null, env:Vector.<String> = null, afterStackSize:int = 65536):void

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).

write16()method 
public static function write16(ptr:int, value:int):void

Write the low 16 bits of value into domainMemory.

Parameters

ptr:int — The address of the location in domainMemory to write to
 
value:int — The value to write (only the low 16 bits are written)

write32()method 
public static function write32(ptr:int, value:int):void

Write a 32 bit value into domainMemory

Parameters

ptr:int — The address of the location in domainMemory to write to
 
value:int — The value to write

write8()method 
public static function write8(ptr:int, value:int):void

Write the low 8 bits of value into domainMemory.

Parameters

ptr:int — The address of the location in domainMemory to write to
 
value:int — The value to write (only the low 8 bits are written)

writeBytes()method 
public static function writeBytes(ptr:int, length:uint, source:IDataInput):void

Copy the contents of an object that implements the IDataInput interface (ByteArray, FileStream, Socket etc) into domainMemory.

Parameters

ptr:int — The address of the location in domainMemory to start writting to
 
length:uint — The number of bytes to copy from the source bytearray (starting from source.position)
 
source:IDataInput — The IDataInput to copy data from (the current position in this IDataInput will be used, and will increase by length)

writeDouble()method 
public static function writeDouble(ptr:int, value:Number):void

Write a Number as a 64 bit float into domainMemory

Parameters

ptr:int — The address of the location in domainMemory to write to
 
value:Number — The value to write at the address

writeFloat()method 
public static function writeFloat(ptr:int, value:Number):void

Write a Number as a 32 bit float into domainMemory

Parameters

ptr:int — The address of the location in domainMemory to write to
 
value:Number — The value to write at the address (will be rounded to the nearest 32bit floating point value)

writeIntVector()method 
public static function writeIntVector(ptr:int, vec:Vector.<int>):void

Write a Vector of ints into domainMemory starting at offset ptr.

Parameters

ptr:int — The offset in domainMemory to start writing to
 
vec:Vector.<int> — The Vector of ints to write into domainMemory

writeString()method 
public static function writeString(ptr:int, s:String):int

Write an actionscript string as UTF8 data into domainMemory

Parameters

ptr:int — The location in domainMemory where the string will be written. You must ensure that this points to a buffer in the flascc world that has enough space to hold the string data or this method will overwrite other data within your program. Consider using mallocString instead as it will allocate the correct amount of space.
 
s:String

Returns
int — The number of bytes written