Skip to content

Commit a8a6b41

Browse files
committed
Struct Documentation
1 parent a98a2f8 commit a8a6b41

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/structs.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
## This Page Is A Work In Progress
1+
Structs is Masterminds equivalent of C structs it is a method of grouping multiple related variables together.
2+
Since Mastermind only supports one primitive data type this means that Structs are collections of one or more cell data types (single or array cells).
3+
4+
Structs can be used to mimic the styles of object orientated code by adding a struct and a series of related functions that
5+
interface with specific structs to almost form a set of class methods. This forms the basis for Masterminds standard library.
6+
7+
Below is example code for how to use Structs
8+
9+
```
10+
struct box {
11+
cell height;
12+
cell width;
13+
}
14+
15+
def area(struct box boxArg, cell output) {
16+
output = 0;
17+
// height * width
18+
copy boxArg.width {
19+
output += boxArg.height
20+
}
21+
}
22+
23+
sturct box MyBox;
24+
MyBox.height = 12;
25+
MyBox.width = 13;
26+
cell area;
27+
area(MyBox, area);
28+
//area should now equal 156
29+
```
30+
31+
Below is an example for a struct using arrays
32+
33+
```
34+
struct grid {
35+
cell x1[3];
36+
cell x2[3];
37+
cell x3[3];
38+
}
39+
```

0 commit comments

Comments
 (0)