AngelScript cannot automatically determine relationships between registered classes, so in order to establish the hierarchies for use within the script language it is necessary to do a bit more registration beyond the normal object registration.
Hierarchies can currently only be registered for reference types, not for value types.
In order to let AngelScript know that two types are related you need to register the reference cast operators opCast and opImplCast. The opCast should be used if you only want to allow the cast through an explicit call with the cast<class>
operator. opImplCast should be used when you want to allow the compiler to implicitly perform the cast as necessary.
Usually you'll want to use opImplCast for casts from a derived type to the base type, and opCast for casts from a base type to a derived type.
Note that it may be necessary to add extra parenthesis to the asFUNCTION
macro so that the preprocessor doesn't interpret the ,
in the template declaration as the argument separator in the macro.
Just as relationships cannot be determined, there is also no way to automatically let AngelScript add inherited methods and properties to derived types. The reason for this is that method pointers and property offsets may differ between the base class and derived class, especially when multiple inheritance is used, and there is no way to automatically determine exactly what the difference is.
For this reason the application needs to register all the inherited methods and properties for the derived classes, which may lead to a bit of duplicate code. However, you may be able to avoid the duplication through a bit of clever thinking. Here is an example of registering the methods and properties for a base class and the derived class (registration of behaviours has been omitted for briefness):