| AngelScript |

Objects and handles

# Objects

There are two forms of objects, reference types and value types.

Value types behave much like the primitive types, in that they are allocated on the stack and deallocated when the variable goes out of scope. Only the application can register these types, so you need to check with the application's documentation for more information about the registered types.

Reference types are allocated on the memory heap, and may outlive the initial variable that allocates them if another reference to the instance is kept. All script declared classes are reference types. Interfaces are a special form of reference types, that cannot be instantiated, but can be used to access the objects that implement the interfaces without knowing exactly what type of object it is.

      obj o;      // An object is instantiated
      o = obj();  // A temporary instance is created whose
                  // value is assigned to the variable

# Object handles

Object handles are a special type that can be used to hold references to other objects. When calling methods or accessing properties on a variable that is an object handle you will be accessing the actual object that the handle references, just as if it was an alias. Note that unless initialized with the handle of an object, the handle is `null`.

      obj o;
      obj@ a;           // a is initialized to null
      obj@ b = @o;      // b holds a reference to o

      b.ModifyMe();     // The method modifies the original object

      if( a is null )   // Verify if the object points to an object
      {
        @a = @b;        // Make a hold a reference to the same object as b
      }

Not all types allow a handle to be taken. Neither of the primitive types can have handles, and there may exist some object types that do not allow handles. Which objects allow handles or not, are up to the application that registers them.

Object handle and array type modifiers can be combined to form handles to arrays, or arrays of handles, etc.

See also
  Object handles