Add highlighting to struct_definition.md
This commit is contained in:
@@ -4,7 +4,7 @@ Define a struct with the `struct` keyword.
|
||||
|
||||
Syntax:
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct StructName {
|
||||
...
|
||||
}
|
||||
@@ -27,7 +27,7 @@ Inside the struct body, you can:
|
||||
|
||||
A field in a struct is defined in the same way as a variable.
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
x = 5
|
||||
}
|
||||
@@ -39,7 +39,7 @@ This creates a field named `x` with a default value of `5`.
|
||||
|
||||
A method in a struct is defined in the same way as a named function.
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
def myMethod() int {
|
||||
return 0
|
||||
@@ -50,7 +50,7 @@ struct MyStruct {
|
||||
Methods have access to the struct's members through the `self` object, which is implicitly passed.
|
||||
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
|
||||
x = 10
|
||||
@@ -71,7 +71,7 @@ All other fields are public, meaning anywhere in the program can read or write t
|
||||
|
||||
Methods and special methods are by default protected, however can be made private.
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
private x = 10
|
||||
protected y = "Hi"
|
||||
@@ -92,7 +92,7 @@ A constructor is used to initialize an object with user-provided fields.
|
||||
|
||||
Define a constructor like this:
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
constructor(args) {
|
||||
...
|
||||
@@ -110,7 +110,7 @@ where:
|
||||
|
||||
Use a constructor like this:
|
||||
|
||||
```
|
||||
```solstice
|
||||
MyStruct(args)
|
||||
```
|
||||
|
||||
@@ -123,7 +123,7 @@ A destructor is used to destroy an object once it goes out of scope.
|
||||
|
||||
Define a destructor like this:
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
destructor {
|
||||
...
|
||||
@@ -144,7 +144,7 @@ A duplicator is used to copy an object when it is assigned to a new name, or pas
|
||||
|
||||
Define a duplicator like this:
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
duplicator {
|
||||
...
|
||||
@@ -166,7 +166,7 @@ As methods allow easy conversion between different types.
|
||||
|
||||
Define an as method like this:
|
||||
|
||||
```
|
||||
```solstice
|
||||
struct MyStruct {
|
||||
as type {
|
||||
...
|
||||
@@ -182,7 +182,7 @@ where:
|
||||
|
||||
Use an as method like this:
|
||||
|
||||
```
|
||||
```solstice
|
||||
myobj as type
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user