AngelScript
any object

Path: /sdk/add_on/scriptany/

The any type is a generic container that can hold any value. It is a reference type.

The type is registered with RegisterScriptAny(asIScriptEngine*).

Public C++ interface

class CScriptAny
{
public:
// Constructors
CScriptAny(asIScriptEngine *engine);
CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine);
// Memory management
int AddRef() const;
int Release() const;
// Copy the stored value from another any object
CScriptAny &operator=(const CScriptAny&);
int CopyFrom(const CScriptAny *other);
// Store the value, either as variable type, integer number, or real number
void Store(void *ref, int refTypeId);
void Store(asINT64 &value);
void Store(double &value);
// Retrieve the stored value, either as variable type, integer number, or real number
bool Retrieve(void *ref, int refTypeId) const;
bool Retrieve(asINT64 &value) const;
bool Retrieve(double &value) const;
// Get the type id of the stored value
int GetTypeId() const;
};

Public script interface

  class any
  {
    any();
    any(? &in value);
    any(int64 &in value);
    any(double &in value);
    any &opAssign(const any &in other);
    void store(? &in value);
    void store(int64 &in value);
    void store(double &in value);
    bool retrieve(? &out value) const;
    bool retrieve(int64 &out value) const;
    bool retrieve(double &out value) const;
  }

any()
any(? &in value)
any(int64 &in value)
any(double &in value)

The default constructor creates an empty object, and the second initializes the object with the provided value.

The int64 and double overloads make sure that all numbers are converted to 64bit before being stored in the object.

any &opAssign(const any &in other)

The assignment operator will copy the contained value from the other object.

void store(? &in value)
void store(int64 &in value)
void store(double &in value)

These methods sets the value in the object.

The int64 and double overloads make sure that all numbers are converted to 64bit before being stored in the object.

bool retrieve(? &out value) const
bool retrieve(int64 &out value) const
bool retrieve(double &out value) const

These methods retrieve the value stored in the object. The methods will return true if the stored value is compatible with the requested type.

Example usage

In the scripts it can be used as follows:

  int value;
  obj object;
  obj @handle;
  any a,b,c;
  a.store(value);      // store the value
  b.store(@handle);    // store an object handle
  c.store(object);     // store a copy of the object
  a.retrieve(value);   // retrieve the value
  b.retrieve(@handle); // retrieve the object handle
  c.retrieve(object);  // retrieve a copy of the object

In C++ the type can be used as follows:

CScriptAny *myAny;
int typeId = engine->GetTypeIdByDecl("string@");
CScriptString *str = new CScriptString("hello world");
myAny->Store((void*)&str, typeId);
myAny->Retrieve((void*)&str, typeId);
asINT64
__int64 asINT64
64 bit integer
Definition: angelscript.h:620
asIScriptEngine
The engine interface.
Definition: angelscript.h:1092
asIScriptEngine::GetTypeIdByDecl
virtual int GetTypeIdByDecl(const char *decl) const =0
Returns a type id by declaration.