You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ios/blocks.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ star
29
29
30
30

31
31
32
-
**Note:**there is a subtle distinction between the code above and the code below:
32
+
**Note:**There is a subtle distinction between the code above and the code below:
33
33
34
34
```swift
35
35
define star path {
@@ -80,5 +80,41 @@ star {
80
80
81
81

82
82
83
+
## Children
84
+
85
+
ShapeScript's [builder](builders.md) and [csg](csg.md) block commands accept child shapes which they use as inputs to construct a mesh:
86
+
87
+
```swift
88
+
difference {
89
+
cube { size 1 }
90
+
sphere { size 1.1 }
91
+
}
92
+
```
93
+
94
+
You can do the same with your own custom blocks by using the `children` property. This property is available inside a block definition, and returns a [tuple](literals.md#vectors-and-tuples) of whatever child objects were passed in by the caller.
95
+
96
+
Here is a simple block that takes whatever child objects are passed in and stacks them vertically along the Y-axis:
97
+
98
+
```swift
99
+
// define reusable stack command
100
+
define stack {
101
+
for mesh in children {
102
+
mesh
103
+
translate 0 mesh.bounds.size.height
104
+
}
105
+
}
106
+
107
+
// stack some shapes
108
+
stack {
109
+
cube { color red }
110
+
sphere { color green }
111
+
cone { color blue }
112
+
}
113
+
```
114
+
115
+

116
+
117
+
**Note:** The children passed to a block can be any type, not just paths or meshes. ShapeScript uses [type inference](https://en.wikipedia.org/wiki/Type_inference) to raise an error if the caller passes children of a different type than the block expects.
Copy file name to clipboardExpand all lines: docs/ios/functions.md
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,7 +297,45 @@ define almostEqual(a b) {
297
297
}
298
298
```
299
299
300
-
Unlike [block options](blocks.md#options), function inputs do not have default values. Calling a function without passing a value for every input will result in an error.
300
+
**Note:** Unlike [block options](blocks.md#options), function parameters do not have default values. Calling a function without passing a value for every parameter will result in an error.
301
+
302
+
ShapeScript uses [type inference](https://en.wikipedia.org/wiki/Type_inference) to raise an error if the caller passes values of a different type than the function expects.
303
+
304
+
Function parameters can be any type, including paths and meshes. Here is a function that splits a shape into horizontal slices:
Copy file name to clipboardExpand all lines: docs/mac/blocks.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ star
29
29
30
30

31
31
32
-
**Note:**there is a subtle distinction between the code above and the code below:
32
+
**Note:**There is a subtle distinction between the code above and the code below:
33
33
34
34
```swift
35
35
define star path {
@@ -80,5 +80,41 @@ star {
80
80
81
81

82
82
83
+
## Children
84
+
85
+
ShapeScript's [builder](builders.md) and [csg](csg.md) block commands accept child shapes which they use as inputs to construct a mesh:
86
+
87
+
```swift
88
+
difference {
89
+
cube { size 1 }
90
+
sphere { size 1.1 }
91
+
}
92
+
```
93
+
94
+
You can do the same with your own custom blocks by using the `children` property. This property is available inside a block definition, and returns a [tuple](literals.md#vectors-and-tuples) of whatever child objects were passed in by the caller.
95
+
96
+
Here is a simple block that takes whatever child objects are passed in and stacks them vertically along the Y-axis:
97
+
98
+
```swift
99
+
// define reusable stack command
100
+
define stack {
101
+
for mesh in children {
102
+
mesh
103
+
translate 0 mesh.bounds.size.height
104
+
}
105
+
}
106
+
107
+
// stack some shapes
108
+
stack {
109
+
cube { color red }
110
+
sphere { color green }
111
+
cone { color blue }
112
+
}
113
+
```
114
+
115
+

116
+
117
+
**Note:** The children passed to a block can be any type, not just paths or meshes. ShapeScript uses [type inference](https://en.wikipedia.org/wiki/Type_inference) to raise an error if the caller passes children of a different type than the block expects.
Copy file name to clipboardExpand all lines: docs/mac/functions.md
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,7 +297,45 @@ define almostEqual(a b) {
297
297
}
298
298
```
299
299
300
-
Unlike [block options](blocks.md#options), function inputs do not have default values. Calling a function without passing a value for every input will result in an error.
300
+
**Note:** Unlike [block options](blocks.md#options), function parameters do not have default values. Calling a function without passing a value for every parameter will result in an error.
301
+
302
+
ShapeScript uses [type inference](https://en.wikipedia.org/wiki/Type_inference) to raise an error if the caller passes values of a different type than the function expects.
303
+
304
+
Function parameters can be any type, including paths and meshes. Here is a function that splits a shape into horizontal slices:
Copy file name to clipboardExpand all lines: docs/src/blocks.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ star
29
29
30
30

31
31
32
-
**Note:**there is a subtle distinction between the code above and the code below:
32
+
**Note:**There is a subtle distinction between the code above and the code below:
33
33
34
34
```swift
35
35
define star path {
@@ -80,5 +80,41 @@ star {
80
80
81
81

82
82
83
+
## Children
84
+
85
+
ShapeScript's [builder](builders.md) and [csg](csg.md) block commands accept child shapes which they use as inputs to construct a mesh:
86
+
87
+
```swift
88
+
difference {
89
+
cube { size 1 }
90
+
sphere { size 1.1 }
91
+
}
92
+
```
93
+
94
+
You can do the same with your own custom blocks by using the `children` property. This property is available inside a block definition, and returns a [tuple](literals.md#vectors-and-tuples) of whatever child objects were passed in by the caller.
95
+
96
+
Here is a simple block that takes whatever child objects are passed in and stacks them vertically along the Y-axis:
97
+
98
+
```swift
99
+
// define reusable stack command
100
+
define stack {
101
+
for mesh in children {
102
+
mesh
103
+
translate 0 mesh.bounds.size.height
104
+
}
105
+
}
106
+
107
+
// stack some shapes
108
+
stack {
109
+
cube { color red }
110
+
sphere { color green }
111
+
cone { color blue }
112
+
}
113
+
```
114
+
115
+

116
+
117
+
**Note:** The children passed to a block can be any type, not just paths or meshes. ShapeScript uses [type inference](https://en.wikipedia.org/wiki/Type_inference) to raise an error if the caller passes children of a different type than the block expects.
Copy file name to clipboardExpand all lines: docs/src/functions.md
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,7 +297,45 @@ define almostEqual(a b) {
297
297
}
298
298
```
299
299
300
-
Unlike [block options](blocks.md#options), function inputs do not have default values. Calling a function without passing a value for every input will result in an error.
300
+
**Note:** Unlike [block options](blocks.md#options), function parameters do not have default values. Calling a function without passing a value for every parameter will result in an error.
301
+
302
+
ShapeScript uses [type inference](https://en.wikipedia.org/wiki/Type_inference) to raise an error if the caller passes values of a different type than the function expects.
303
+
304
+
Function parameters can be any type, including paths and meshes. Here is a function that splits a shape into horizontal slices:
0 commit comments