Our example demonstrates the concept of struct embedding to achieve seamless composition of types. Here’s the full source code translated to AngelScript.
To run the translated AngelScript example:
Explanation:
Class Definition: Defines the Base class with a property num and a method describe() returning a string.
Container Class: Defines a container class Container which contains an instance of Base and an additional string property str.
Main Function: In the main function, we create an instance of Container, initialize its properties, and demonstrate accessing the properties directly or via the embedded type.
Interface Implementation:
Defines an interface Describer with a method describe().
The TestDescriber function shows how embedding can be used to bestow interface implementations onto other classes by casting the embedded Base class to the Describer interface.
Running the Code: A Run function calls the main() and TestDescriber() functions to demonstrate the full functionality.
This example illustrates the concept of embedding and method inheritance in AngelScript, showing how it can effectively compose complex types.