|
CANCapture Scripting
|
When registering a value type, the size of the type must be given so that AngelScript knows how much space is needed for it. If the type doesn't require any special treatment, i.e. doesn't contain any pointers or other resource references that must be maintained, then the type can be registered with the flag asOBJ_POD. In this case AngelScript doesn't require the default constructor, assignment behaviour, or destructor as it will be able to automatically handle these cases the same way it handles built-in primitives.
If the type will be passed to and from the application by value using native calling conventions, it is important to inform AngelScript of its real type in C++, otherwise AngelScript won't be able to determine exactly how C++ is treating the type in a parameter or return value.
There are a few different flags for this:
| asOBJ_APP_CLASS | The C++ type is a class, struct, or union |
| asOBJ_APP_CLASS_CONSTRUCTOR | The C++ type has a defined constructor |
| asOBJ_APP_CLASS_DESTRUCTOR | The C++ type has a defined destructor |
| asOBJ_APP_CLASS_ASSIGNMENT | The C++ type has a defined assignment operator |
| asOBJ_APP_PRIMITIVE | The C++ type is a C++ primitive, but not a float or double |
| asOBJ_APP_FLOAT | The C++ type is a float or double |
Note that these don't represent how the type will behave in the script language, only what the real type is in the host application. So if you want to register a C++ class that you want to behave as a primitive type in the script language you should still use the flag asOBJ_APP_CLASS. The same thing for the flags to identify that the class has a constructor, destructor, or assignment. These flags tell AngelScript that the class has the respective function, but not that the type in the script language should have these behaviours.
For class types there are also a shorter form of the flags for each combination of the 4 flags. They are of the form asOBJ_APP_CLASS_CDA, where the existance of the last letters determine if the constructor, destructor, and/or assignment behaviour are available. For example asOBJ_APP_CLASS_CDA is defined as asOBJ_APP_CLASS | asOBJ_APP_CLASS_CONSTRUCTOR | asOBJ_APP_CLASS_DESTRUCTOR | asOBJ_APP_CLASS_ASSIGNMENT.
If a constructor or destructor is needed they shall be registered the following way:
The assignment behaviour is registered the same way as for reference types.
1.8.3.1