CANCapture Scripting
List of all members
asIScriptModule Class Referenceabstract

The interface to the script modules.

Public Member Functions

Miscellaneous
virtual asIScriptEngineGetEngine ()=0
 Returns a pointer to the engine. More...
 
virtual void SetName (const char *name)=0
 Sets the name of the module. More...
 
virtual const char * GetName ()=0
 Gets the name of the module. More...
 
Compilation
virtual int AddScriptSection (const char *name, const char *code, size_t codeLength=0, int lineOffset=0)=0
 Add a script section for the next build. More...
 
virtual int Build ()=0
 Build the previously added script sections. More...
 
Functions
virtual int GetFunctionCount ()=0
 Returns the number of global functions in the module. More...
 
virtual int GetFunctionIdByIndex (int index)=0
 Returns the function id by index. More...
 
virtual int GetFunctionIdByName (const char *name)=0
 Returns the function id by name. More...
 
virtual int GetFunctionIdByDecl (const char *decl)=0
 Returns the function id by declaration. More...
 
virtual asIScriptFunctionGetFunctionDescriptorByIndex (int index)=0
 Returns the function descriptor for the script function. More...
 
virtual asIScriptFunctionGetFunctionDescriptorById (int funcId)=0
 Returns the function descriptor for the script function. More...
 
Global variables
virtual int ResetGlobalVars ()=0
 Reset the global variables of the module. More...
 
virtual int GetGlobalVarCount ()=0
 Returns the number of global variables in the module. More...
 
virtual int GetGlobalVarIndexByName (const char *name)=0
 Returns the global variable index by name. More...
 
virtual int GetGlobalVarIndexByDecl (const char *decl)=0
 Returns the global variable index by declaration. More...
 
virtual const char * GetGlobalVarDeclaration (int index)=0
 Returns the global variable declaration. More...
 
virtual const char * GetGlobalVarName (int index)=0
 Returns the global variable name. More...
 
virtual int GetGlobalVarTypeId (int index, bool *isConst=0)=0
 Returns the type id for the global variable. More...
 
virtual void * GetAddressOfGlobalVar (int index)=0
 Returns the pointer to the global variable. More...
 
Type identification
virtual int GetObjectTypeCount ()=0
 Returns the number of object types. More...
 
virtual asIObjectTypeGetObjectTypeByIndex (asUINT index)=0
 Returns the object type interface by index. More...
 
virtual int GetTypeIdByDecl (const char *decl)=0
 Returns a type id by declaration. More...
 
Enums
virtual int GetEnumCount ()=0
 Returns the number of enum types declared in the module. More...
 
virtual const char * GetEnumByIndex (asUINT index, int *enumTypeId)=0
 Returns the enum type. More...
 
virtual int GetEnumValueCount (int enumTypeId)=0
 Returns the number of values defined for the enum type. More...
 
virtual const char * GetEnumValueByIndex (int enumTypeId, asUINT index, int *outValue)=0
 Returns the name and value of the enum value. More...
 
Typedefs
virtual int GetTypedefCount ()=0
 Returns the number of typedefs in the module. More...
 
virtual const char * GetTypedefByIndex (asUINT index, int *typeId)=0
 Returns the typedef. More...
 
Dynamic binding between modules
virtual int GetImportedFunctionCount ()=0
 Returns the number of functions declared for import. More...
 
virtual int GetImportedFunctionIndexByDecl (const char *decl)=0
 Returns the imported function index by declaration. More...
 
virtual const char * GetImportedFunctionDeclaration (int importIndex)=0
 Returns the imported function declaration. More...
 
virtual const char * GetImportedFunctionSourceModule (int importIndex)=0
 Returns the declared imported function source module. More...
 
virtual int BindImportedFunction (int importIndex, int funcId)=0
 Binds an imported function to the function from another module. More...
 
virtual int UnbindImportedFunction (int importIndex)=0
 Unbinds an imported function. More...
 
virtual int BindAllImportedFunctions ()=0
 Binds all imported functions in a module, by searching their equivalents in the declared source modules. More...
 
virtual int UnbindAllImportedFunctions ()=0
 Unbinds all imported functions. More...
 
Bytecode saving and loading
virtual int SaveByteCode (asIBinaryStream *out)=0
 Save compiled bytecode to a binary stream. More...
 
virtual int LoadByteCode (asIBinaryStream *in)=0
 Load pre-compiled bytecode from a binary stream. More...
 

Member Function Documentation

virtual int asIScriptModule::AddScriptSection ( const char *  name,
const char *  code,
size_t  codeLength = 0,
int  lineOffset = 0 
)
pure virtual
Parameters
[in]nameThe name of the script section
[in]codeThe script code buffer
[in]codeLengthThe length of the script code
[in]lineOffsetAn offset that will be added to compiler message line numbers
Returns
A negative value on error.
Return values
asMODULE_IS_IN_USEThe module is currently in use.

This adds a script section to the module. All sections added will be treated as if one large script. Errors reported will give the name of the corresponding section.

The code added is copied by the engine, so there is no need to keep the original buffer after the call. Note that this can be changed by setting the engine property asEP_COPY_SCRIPT_SECTIONS with asIScriptEngine::SetEngineProperty.

virtual int asIScriptModule::BindAllImportedFunctions ( )
pure virtual
Returns
A negative value on error.
Return values
asERRORAn error occurred.
asCANT_BIND_ALL_FUNCTIONSNot all functions where bound.

This functions tries to bind all imported functions in the module by searching for matching functions in the suggested modules. If a function cannot be bound the function will give an error asCANT_BIND_ALL_FUNCTIONS, but it will continue binding the rest of the functions.

virtual int asIScriptModule::BindImportedFunction ( int  importIndex,
int  funcId 
)
pure virtual
Parameters
[in]importIndexThe index of the imported function.
[in]funcIdThe function id of the function that will be bound to the imported function.
Returns
A negative value on error.
Return values
asNO_FUNCTIONimportIndex or fundId is incorrect.
asINVALID_INTERFACEThe signature of function doesn't match the import statement.

The imported function is only bound if the functions have the exact same signature, i.e the same return type, and parameters.

virtual int asIScriptModule::Build ( )
pure virtual
Returns
A negative value on error
Return values
asINVALID_CONFIGURATIONThe engine configuration is invalid.
asERRORThe script failed to build.
asBUILD_IN_PROGRESSAnother thread is currently building.

Builds the script based on the added sections, and registered types and functions. After the build is complete the script sections are removed to free memory. If the script module needs to be rebuilt all of the script sections needs to be added again.

Compiler messages are sent to the message callback function set with asIScriptEngine::SetMessageCallback. If there are no errors or warnings, no messages will be sent to the callback function.

virtual void* asIScriptModule::GetAddressOfGlobalVar ( int  index)
pure virtual
Parameters
[in]indexThe index of the global variable.
Returns
A pointer to the global variable, or null if not found.

This method should be used to retrieve the pointer of a variable that you wish to access.

virtual asIScriptEngine* asIScriptModule::GetEngine ( )
pure virtual
Returns
A pointer to the engine.
virtual const char* asIScriptModule::GetEnumByIndex ( asUINT  index,
int *  enumTypeId 
)
pure virtual
Parameters
[in]indexThe index of the enum type.
[out]enumTypeIdReceives the type id of the enum type.
Returns
The name of the enum type, or null on error.
virtual int asIScriptModule::GetEnumCount ( )
pure virtual
Returns
The number of enum types in the module.
virtual const char* asIScriptModule::GetEnumValueByIndex ( int  enumTypeId,
asUINT  index,
int *  outValue 
)
pure virtual
Parameters
[in]enumTypeIdThe type id of the enum type.
[in]indexThe index of the enum value.
[out]outValueReceives the numeric value.
Returns
The name of the enum value.
virtual int asIScriptModule::GetEnumValueCount ( int  enumTypeId)
pure virtual
Parameters
[in]enumTypeIdThe type id of the enum type.
Returns
The number of enum values or a negative value on error.
Return values
asINVALID_ARGenumTypeId is not an enum type.
virtual int asIScriptModule::GetFunctionCount ( )
pure virtual
Returns
A negative value on error, or the number of global functions in this module.
Return values
asERRORThe module was not compiled successfully.

This method retrieves the number of compiled script functions.

virtual asIScriptFunction* asIScriptModule::GetFunctionDescriptorById ( int  funcId)
pure virtual
Parameters
[in]funcIdThe id of the function or method.
Returns
A pointer to the function description interface, or null if not found.
virtual asIScriptFunction* asIScriptModule::GetFunctionDescriptorByIndex ( int  index)
pure virtual
Parameters
[in]indexThe index of the function.
Returns
A pointer to the function description interface, or null if not found.
virtual int asIScriptModule::GetFunctionIdByDecl ( const char *  decl)
pure virtual
Parameters
[in]declThe function signature.
Returns
A negative value on error, or the function id.
Return values
asERRORThe module was not compiled successfully.
asINVALID_DECLARATIONThe decl is invalid.
asMULTIPLE_FUNCTIONSFound multiple matching functions.
asNO_FUNCTIONDidn't find any matching functions.

This method should be used to retrieve the id of the script function that you wish to execute. The id is then sent to the context's Prepare method.

The method will find the script function with the exact same declaration.

virtual int asIScriptModule::GetFunctionIdByIndex ( int  index)
pure virtual
Parameters
[in]indexThe index of the function.
Returns
A negative value on error, or the function id.
Return values
asNO_FUNCTIONThere is no function with that index.

This method should be used to retrieve the id of the script function that you wish to execute. The id is then sent to the context's Prepare method.

virtual int asIScriptModule::GetFunctionIdByName ( const char *  name)
pure virtual
Parameters
[in]nameThe name of the function.
Returns
A negative value on error, or the function id.
Return values
asERRORThe module was not compiled successfully.
asMULTIPLE_FUNCTIONSFound multiple matching functions.
asNO_FUNCTIONDidn't find any matching functions.

This method should be used to retrieve the id of the script function that you wish to execute. The id is then sent to the context's Prepare method.

virtual int asIScriptModule::GetGlobalVarCount ( )
pure virtual
Returns
A negative value on error, or the number of global variables in the module.
Return values
asERRORThe module was not compiled successfully.
virtual const char* asIScriptModule::GetGlobalVarDeclaration ( int  index)
pure virtual
Parameters
[in]indexThe index of the global variable.
Returns
A null terminated string with the variable declaration, or null if not found.

This method can be used to retrieve the variable declaration of the script variables that the host application will access. Verifying the declaration is important because, even though the script may compile correctly the user may not have used the variable types as intended.

virtual int asIScriptModule::GetGlobalVarIndexByDecl ( const char *  decl)
pure virtual
Parameters
[in]declThe global variable declaration.
Returns
A negative value on error, or the global variable index.
Return values
asERRORThe module was not built successfully.
asNO_GLOBAL_VARThe matching global variable was found.

This method should be used to retrieve the index of the script variable that you wish to access.

The method will find the script variable with the exact same declaration.

virtual int asIScriptModule::GetGlobalVarIndexByName ( const char *  name)
pure virtual
Parameters
[in]nameThe name of the global variable.
Returns
A negative value on error, or the global variable index.
Return values
asERRORThe module was not built successfully.
asNO_GLOBAL_VARThe matching global variable was found.

This method should be used to retrieve the index of the script variable that you wish to access.

virtual const char* asIScriptModule::GetGlobalVarName ( int  index)
pure virtual
Parameters
[in]indexThe index of the global variable.
Returns
A null terminated string with the variable name, or null if not found.
virtual int asIScriptModule::GetGlobalVarTypeId ( int  index,
bool *  isConst = 0 
)
pure virtual
Parameters
[in]indexThe index of the global variable.
[out]isConstReceives the constness indicator of the variable.
Returns
The type id of the global variable, or a negative value on error.
Return values
asINVALID_ARGThe index is out of range.
virtual int asIScriptModule::GetImportedFunctionCount ( )
pure virtual
Returns
A negative value on error, or the number of imported functions.
Return values
asERRORThe module was not built successfully.

This function returns the number of functions that are imported in a module. These functions need to be bound before they can be used, or a script exception will be thrown.

virtual const char* asIScriptModule::GetImportedFunctionDeclaration ( int  importIndex)
pure virtual
Parameters
[in]importIndexThe index of the imported function.
Returns
A null terminated string with the function declaration, or null if not found.

Use this function to get the declaration of the imported function. The returned declaration can be used to find a matching function in another module that can be bound to the imported function.

virtual int asIScriptModule::GetImportedFunctionIndexByDecl ( const char *  decl)
pure virtual
Parameters
[in]declThe function declaration of the imported function.
Returns
A negative value on error, or the index of the imported function.
Return values
asERRORThe module was not built successfully.
asMULTIPLE_FUNCTIONSFound multiple matching functions.
asNO_FUNCTIONDidn't find any matching function.

This function is used to find a specific imported function by its declaration.

virtual const char* asIScriptModule::GetImportedFunctionSourceModule ( int  importIndex)
pure virtual
Parameters
[in]importIndexThe index of the imported function.
Returns
A null terminated string with the name of the source module, or null if not found.

Use this function to get the name of the suggested module to import the function from.

virtual const char* asIScriptModule::GetName ( )
pure virtual
Returns
The name of the module.
virtual asIObjectType* asIScriptModule::GetObjectTypeByIndex ( asUINT  index)
pure virtual
Parameters
[in]indexThe index of the type.
Returns
The object type interface for the type, or null if not found.
virtual int asIScriptModule::GetObjectTypeCount ( )
pure virtual
Returns
The number of object types declared in the module.
virtual const char* asIScriptModule::GetTypedefByIndex ( asUINT  index,
int *  typeId 
)
pure virtual
Parameters
[in]indexThe index of the typedef.
[out]typeIdThe type that the typedef aliases.
Returns
The name of the typedef.
virtual int asIScriptModule::GetTypedefCount ( )
pure virtual
Returns
The number of typedefs in the module.
virtual int asIScriptModule::GetTypeIdByDecl ( const char *  decl)
pure virtual
Parameters
[in]declThe declaration of the type.
Returns
A negative value on error, or the type id of the type.
Return values
asINVALID_TYPEdecl is not a valid type.

Translates a type declaration into a type id. The returned type id is valid for as long as the type is valid, so you can safely store it for later use to avoid potential overhead by calling this function each time. Just remember to update the type id, any time the type is changed within the engine, e.g. when recompiling script declared classes, or changing the engine configuration.

The type id is based on a sequence number and depends on the order in which the type ids are queried, thus is not guaranteed to always be the same for each execution of the application. The asETypeIdFlags can be used to obtain some information about the type directly from the id.

A base type yields the same type id whether the declaration is const or not, however if the const is for the subtype then the type id is different, e.g. string@ isn't the same as const string@ but string is the same as const string.

virtual int asIScriptModule::LoadByteCode ( asIBinaryStream in)
pure virtual
Parameters
[in]inThe input stream.
Returns
A negative value on error.
Return values
asINVALID_ARGThe stream object wasn't specified.
asBUILD_IN_PROGRESSAnother thread is currently building.

This method is used to load pre-compiled byte code from disk or memory. The application must implement an object that inherits from asIBinaryStream to provide the necessary stream operations.

It is expected that the application performs the necessary validations to make sure the pre-compiled byte code is from a trusted source. The application should also make sure the pre-compiled byte code is compatible with the current engine configuration, i.e. that the engine has been configured in the same way as when the byte code was first compiled.

virtual int asIScriptModule::ResetGlobalVars ( )
pure virtual
Returns
A negative value on error.
Return values
asERRORThe module was not compiled successfully.

Resets the global variables declared in this module to their initial value.

virtual int asIScriptModule::SaveByteCode ( asIBinaryStream out)
pure virtual
Parameters
[in]outThe output stream.
Returns
A negative value on error.
Return values
asINVALID_ARGThe stream object wasn't specified.

This method is used to save pre-compiled byte code to disk or memory, for a later restoral. The application must implement an object that inherits from asIBinaryStream to provide the necessary stream operations.

The pre-compiled byte code is currently not platform independent, so you need to make sure the byte code is compiled on a platform that is compatible with the one that will load it.

virtual void asIScriptModule::SetName ( const char *  name)
pure virtual
Parameters
[in]nameThe new name.

Sets the name of the script module.

virtual int asIScriptModule::UnbindAllImportedFunctions ( )
pure virtual
Returns
A negative value on error.

Unbinds all imported functions in the module.

virtual int asIScriptModule::UnbindImportedFunction ( int  importIndex)
pure virtual
Parameters
[in]importIndexThe index of the imported function.
Returns
A negative value on error.
Return values
asINVALID_ARGThe index is not valid. Unbinds the imported function.