Path: /sdk/add_on/scriptarray/
The array
type is a template object that allow the scripts to declare arrays of any type. Since it is a generic class it is not the most performatic due to the need to determine characteristics at runtime. For that reason it is recommended that the application registers a template specialization for the array types that are most commonly used.
The type is registered with RegisterScriptArray(asIScriptEngine *engine, bool defaultArrayType)
. The second parameter should be set to true if you wish to allow the syntax form type[]
to declare arrays.
Compile the add-on with the pre-processor define AS_USE_STLNAMES=1 to register the methods with the same names as used by C++ STL where the methods have the same significance. Not all methods from STL is implemented in the add-on, but many of the most frequent once are so a port from script to C++ and vice versa might be easier if STL names are used.
Compile the add-on with the pre-processor define AS_USE_ACCESSORS=1 to register length as a virtual property instead of the method length().
Compile the add-on with the pre-processor define AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE=1 to disable the implicit operations with primitives that automatically formats the primitive values to strings.
Public C++ interface
class CScriptArray
{
public:
static CScriptArray *Create(
asITypeInfo *arrayType,
asUINT length,
void *defaultValue);
static CScriptArray *Create(
asITypeInfo *arrayType,
void *listBuffer);
void AddRef() const;
void Release() const;
int GetArrayTypeId() const;
int GetElementTypeId() const;
bool IsEmpty() const;
void Reserve(
asUINT numElements);
void Resize(
asUINT numElements);
const void *At(
asUINT index)
const;
void SetValue(
asUINT index,
void *value);
CScriptArray &operator=(const CScriptArray&);
bool operator==(const CScriptArray &) const;
void InsertAt(
asUINT index,
void *value);
void InsertLast(void *value);
void RemoveLast();
void SortAsc();
void SortDesc();
void Reverse();
int Find(void *value) const;
int Find(
asUINT startAt,
void *value)
const;
int FindByRef(void *ref) const;
int FindByRef(
asUINT startAt,
void *ref)
const;
void *GetBuffer();
};
void *(* asALLOCFUNC_t)(size_t)
The function signature for the custom memory allocation function.
Definition: angelscript.h:655
unsigned int asUINT
32 bit unsigned integer
Definition: angelscript.h:127
void(* asFREEFUNC_t)(void *)
The function signature for the custom memory deallocation function.
Definition: angelscript.h:657
The interface for a script function description.
Definition: angelscript.h:4031
The interface for describing types This interface is used to describe the types in the script engine.
Definition: angelscript.h:3735
Public script interface
- See also
- Arrays in the script language
C++ example
This function shows how a script array can be instantiated from the application and then passed to the script.
CScriptArray *CreateArrayOfStrings()
{
if( ctx )
{
CScriptArray* arr = CScriptArray::Create(t, 3);
for(
asUINT i = 0; i < arr->GetSize(); i++ )
{
string val("test");
arr->SetValue(i, &val);
}
return arr;
}
return 0;
}
The interface to the virtual machine.
Definition: angelscript.h:2764
virtual asIScriptEngine * GetEngine() const =0
Returns a pointer to the engine.
The engine interface.
Definition: angelscript.h:1125
virtual asITypeInfo * GetTypeInfoByDecl(const char *decl) const =0
Returns a type by declaration.
AS_API asIScriptContext * asGetActiveContext()
Returns the currently active context.