AngelScript: any object

# 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();
      int Release();

      // 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);

        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;
      }

## 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);