Add highlighting to struct_definition.md
This commit is contained in:
@@ -4,7 +4,7 @@ Define a struct with the `struct` keyword.
|
|||||||
|
|
||||||
Syntax:
|
Syntax:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct StructName {
|
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.
|
A field in a struct is defined in the same way as a variable.
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
x = 5
|
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.
|
A method in a struct is defined in the same way as a named function.
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
def myMethod() int {
|
def myMethod() int {
|
||||||
return 0
|
return 0
|
||||||
@@ -50,7 +50,7 @@ struct MyStruct {
|
|||||||
Methods have access to the struct's members through the `self` object, which is implicitly passed.
|
Methods have access to the struct's members through the `self` object, which is implicitly passed.
|
||||||
|
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
|
|
||||||
x = 10
|
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.
|
Methods and special methods are by default protected, however can be made private.
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
private x = 10
|
private x = 10
|
||||||
protected y = "Hi"
|
protected y = "Hi"
|
||||||
@@ -92,7 +92,7 @@ A constructor is used to initialize an object with user-provided fields.
|
|||||||
|
|
||||||
Define a constructor like this:
|
Define a constructor like this:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
constructor(args) {
|
constructor(args) {
|
||||||
...
|
...
|
||||||
@@ -110,7 +110,7 @@ where:
|
|||||||
|
|
||||||
Use a constructor like this:
|
Use a constructor like this:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
MyStruct(args)
|
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:
|
Define a destructor like this:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
destructor {
|
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:
|
Define a duplicator like this:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
duplicator {
|
duplicator {
|
||||||
...
|
...
|
||||||
@@ -166,7 +166,7 @@ As methods allow easy conversion between different types.
|
|||||||
|
|
||||||
Define an as method like this:
|
Define an as method like this:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
struct MyStruct {
|
struct MyStruct {
|
||||||
as type {
|
as type {
|
||||||
...
|
...
|
||||||
@@ -182,7 +182,7 @@ where:
|
|||||||
|
|
||||||
Use an as method like this:
|
Use an as method like this:
|
||||||
|
|
||||||
```
|
```solstice
|
||||||
myobj as type
|
myobj as type
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user