2019-04-02 06:36:03 -07:00
|
|
|
<!-- vim-markdown-toc GFM -->
|
|
|
|
|
2019-08-14 03:31:41 -07:00
|
|
|
* [Structure Definitions](#structure-definitions)
|
|
|
|
* [Example: Structure definitions](#example-structure-definitions)
|
2019-04-02 06:36:03 -07:00
|
|
|
* [Structure Flags](#structure-flags)
|
|
|
|
* [Structure Content](#structure-content)
|
|
|
|
|
|
|
|
<!-- vim-markdown-toc -->
|
|
|
|
|
2019-08-14 03:31:41 -07:00
|
|
|
# Structure Definitions
|
|
|
|
|
2019-04-02 06:36:03 -07:00
|
|
|
A structure is an object type that does not inherit from Object and is not
|
|
|
|
always (though occasionally is) a reference type, unlike classes. Structures
|
|
|
|
marked as `native` are passed by-reference to and from the engine in an
|
|
|
|
implicit pseudo-type `Pointer<T>`, and `null` can be passed in their place.
|
|
|
|
Also note that this means the engine can return `null` structures. Non-native
|
|
|
|
structures cannot be passed as arguments or returned normally.
|
|
|
|
|
|
|
|
Structures are preferred for basic compound data types that do not need to be
|
|
|
|
instanced and are often used as a way of generalizing code. They cannot be
|
|
|
|
returned from functions.
|
|
|
|
|
|
|
|
Structures are subject to Scoping.
|
|
|
|
|
|
|
|
A structure takes the form of:
|
|
|
|
|
|
|
|
```
|
|
|
|
struct Identifier $[Structure-flags...]$
|
|
|
|
{
|
2019-08-14 03:38:33 -07:00
|
|
|
$[Structure-content...]$
|
2019-04-02 06:36:03 -07:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Optionally followed by a semicolon.
|
|
|
|
|
|
|
|
## Example: Structure definitions
|
|
|
|
|
|
|
|
```
|
2019-04-05 16:34:55 -07:00
|
|
|
// Simple structure.
|
2019-04-02 06:36:03 -07:00
|
|
|
struct MyCoolStructure
|
|
|
|
{
|
2019-08-14 03:38:33 -07:00
|
|
|
int X;
|
|
|
|
int Y;
|
|
|
|
int Z;
|
2019-04-02 06:36:03 -07:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-04-02 08:28:16 -07:00
|
|
|
# Structure Flags
|
2019-04-02 06:36:03 -07:00
|
|
|
|
|
|
|
| Flag | Description |
|
|
|
|
| ---- | ----------- |
|
|
|
|
| `clearscope` | Structure has Data scope. Default. |
|
|
|
|
| `native` | Structure is from the engine. Only usable internally. |
|
|
|
|
| `play` | Structure has Play scope. |
|
|
|
|
| `ui` | Structure has UI scope. |
|
|
|
|
| `version ( "ver" )` | Restricted to ZScript version `ver` or higher. |
|
|
|
|
|
2019-04-02 08:28:16 -07:00
|
|
|
# Structure Content
|
2019-04-02 06:36:03 -07:00
|
|
|
|
|
|
|
Structure contents are an optional list of various things logically contained
|
|
|
|
within the structure, including:
|
|
|
|
|
2019-08-14 03:31:41 -07:00
|
|
|
* Member declarations
|
|
|
|
* Method definitions
|
|
|
|
* Enumeration definitions
|
|
|
|
* Constant definitions
|
2019-04-02 06:36:03 -07:00
|
|
|
|
|
|
|
<!-- EOF -->
|