@mylasertools/kerfscript 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +201 -1
- package/LANGUAGE.md +169 -30
- package/README.md +8 -2
- package/THIRD-PARTY-NOTICES.md +113 -0
- package/dist/analysis.d.cts +20 -0
- package/dist/analysis.d.ts +20 -0
- package/dist/assembly.d.cts +28 -1
- package/dist/assembly.d.ts +28 -1
- package/dist/ast.d.cts +9 -0
- package/dist/ast.d.ts +9 -0
- package/dist/cli.js +10333 -4650
- package/dist/diff.d.cts +18 -0
- package/dist/diff.d.ts +18 -0
- package/dist/evaluator.d.cts +34 -0
- package/dist/evaluator.d.ts +34 -0
- package/dist/functions.d.cts +1 -0
- package/dist/functions.d.ts +1 -0
- package/dist/geometry.d.cts +22 -0
- package/dist/geometry.d.ts +22 -0
- package/dist/hardware.d.cts +13 -0
- package/dist/hardware.d.ts +13 -0
- package/dist/highlight.cjs +2 -2
- package/dist/highlight.js +2 -2
- package/dist/index.cjs +2278 -52
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +2278 -52
- package/dist/instructions.d.cts +3 -0
- package/dist/instructions.d.ts +3 -0
- package/dist/language.cjs +2235 -50
- package/dist/language.js +2235 -50
- package/dist/libraries.cjs +2211 -26
- package/dist/libraries.d.cts +3 -0
- package/dist/libraries.d.ts +3 -0
- package/dist/libraries.js +2211 -26
- package/dist/png.d.cts +9 -0
- package/dist/png.d.ts +9 -0
- package/dist/render.d.cts +22 -1
- package/dist/render.d.ts +22 -1
- package/dist/signatures.cjs +269 -11
- package/dist/signatures.js +269 -11
- package/dist/slots.d.cts +8 -0
- package/dist/slots.d.ts +8 -0
- package/dist/values.d.cts +6 -1
- package/dist/values.d.ts +6 -1
- package/dist/verify/command.d.cts +1 -0
- package/dist/verify/command.d.ts +1 -0
- package/dist/verify/geometry.d.cts +25 -0
- package/dist/verify/geometry.d.ts +25 -0
- package/dist/verify/index.d.cts +10 -0
- package/dist/verify/index.d.ts +10 -0
- package/dist/verify/joints.d.cts +7 -0
- package/dist/verify/joints.d.ts +7 -0
- package/dist/verify/mechanics.d.cts +11 -0
- package/dist/verify/mechanics.d.ts +11 -0
- package/dist/verify/motion.d.cts +8 -0
- package/dist/verify/motion.d.ts +8 -0
- package/dist/verify/pose.d.cts +5 -0
- package/dist/verify/pose.d.ts +5 -0
- package/dist/verify/relations.d.cts +8 -0
- package/dist/verify/relations.d.ts +8 -0
- package/dist/verify/snapshot.d.cts +11 -0
- package/dist/verify/snapshot.d.ts +11 -0
- package/dist/verify/solids.d.cts +40 -0
- package/dist/verify/solids.d.ts +40 -0
- package/dist/verify/spec.d.cts +9 -0
- package/dist/verify/spec.d.ts +9 -0
- package/dist/verify/summary.d.cts +17 -0
- package/dist/verify/summary.d.ts +17 -0
- package/dist/verify/types.d.cts +301 -0
- package/dist/verify/types.d.ts +301 -0
- package/docs/cli.md +87 -15
- package/docs/javascript.md +57 -25
- package/docs/layers.md +42 -2
- package/docs/library.md +501 -3
- package/docs/parts-and-sheets.md +199 -1
- package/docs/shared-libraries.md +8 -1
- package/docs/specification.md +78 -23
- package/docs/verification.md +363 -0
- package/docs/versions.md +2 -2
- package/package.json +2 -1
- package/dist/import/dbg.d.cts +0 -1
- package/dist/import/dbg.d.ts +0 -1
package/docs/parts-and-sheets.md
CHANGED
|
@@ -59,7 +59,178 @@ a finger edge set to `"out"` where it should be `"in"` looks like, or a part
|
|
|
59
59
|
placed one thickness off. Joints that interlock exactly do not count, and
|
|
60
60
|
neither does an overlap smaller than about a cubic millimetre, the kind of
|
|
61
61
|
nick a laser kerf or a press fit takes up. A tab half a millimetre out of its
|
|
62
|
-
slot is well over that and gets a warning.
|
|
62
|
+
slot is well over that and gets a warning. The warning says roughly where
|
|
63
|
+
in the assembly the two meet.
|
|
64
|
+
|
|
65
|
+
### Turning a part any way
|
|
66
|
+
|
|
67
|
+
`rotate` turns about x, then y, then z. To say where a part's own axes
|
|
68
|
+
point instead, use `orient(x, z)`: the part's x axis along the first
|
|
69
|
+
direction and its top face towards the second.
|
|
70
|
+
|
|
71
|
+
```kerf
|
|
72
|
+
// A panel leaning back 15 degrees, its top face to the front
|
|
73
|
+
part("back", at = [0, 60, 3], rotate = orient([1, 0, 0], [0, -cos(15), sin(15)])) rect([100, 80]);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`rotation([x, y, z])` gives the matrix of a turn, matrices multiply with
|
|
77
|
+
`*`, and `euler(m)` turns a matrix back into angles for `rotate`:
|
|
78
|
+
`euler(rotation([0, 0, 30]) * rotation([90, 0, 0]))` stands a part up, then
|
|
79
|
+
turns it 30 degrees about z.
|
|
80
|
+
|
|
81
|
+
### Placing a group
|
|
82
|
+
|
|
83
|
+
`place(at, rotate) { ... }` moves and turns everything inside it, with
|
|
84
|
+
each part's own placement inside the group's. Build a drawer, a crate or a
|
|
85
|
+
whole library box at the origin and place it where it goes:
|
|
86
|
+
|
|
87
|
+
```kerf
|
|
88
|
+
use <kerf/box>
|
|
89
|
+
|
|
90
|
+
place(at = [20, 10, 30], rotate = [0, 0, 90]) box([80, 60, 40], name = "crate");
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Stacks, mirrored pairs and glued layers
|
|
94
|
+
|
|
95
|
+
- `stack = 3` glues three layers at each placement, one thickness apart:
|
|
96
|
+
thick feet, posts and blocks from thin sheet. The parts list says how
|
|
97
|
+
many make a stack.
|
|
98
|
+
- `material = "red acrylic"` names the material the part is cut from,
|
|
99
|
+
as wrapping it in `material(name = "red acrylic")` would.
|
|
100
|
+
- `mirror = true` cuts the part mirrored left to right. A lopsided end
|
|
101
|
+
plate's other half is the same part mirrored, and its engraving still
|
|
102
|
+
reads the right way round.
|
|
103
|
+
- `glue = "top plate", face = "top"` lays a part on another part's face,
|
|
104
|
+
its `at` and `rotate` measured on that face. Move the plate, and what is
|
|
105
|
+
glued on it moves too. A stack glued under a part (`face = "bottom"`)
|
|
106
|
+
grows down, away from it.
|
|
107
|
+
|
|
108
|
+
```kerf
|
|
109
|
+
part("seat", at = [0, 0, 40]) rect([80, 80], r = 6);
|
|
110
|
+
part("cushion", glue = "seat", at = [6, 6, 0]) rect([68, 68], r = 10);
|
|
111
|
+
part("leg", qty = 4, stack = 4, at = [[0, 0, 0], [70, 0, 0], [0, 70, 0], [70, 70, 0]]) rect([10, 10]);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Slots from the assembly
|
|
115
|
+
|
|
116
|
+
Draw the tabs on one part and let the part they go into cut its own slots:
|
|
117
|
+
`slots = ["back", "divider"]` cuts, through this part, the cross-section of
|
|
118
|
+
those parts wherever their material passes through it in the assembly,
|
|
119
|
+
`clearance = 0.1` wider. It works at any angle, so a back leaning 15
|
|
120
|
+
degrees gets slots as long as its tabs' slanted cross-section, and a strip
|
|
121
|
+
bent by a living hinge cuts slots for the tabs on its straight runs. A part
|
|
122
|
+
must reach 1 mm into it (or half way through a thinner one) to cut a slot,
|
|
123
|
+
and a blind tab's slot goes through: one that only dips into the surface is
|
|
124
|
+
misplaced, and the collision check reports it rather than a
|
|
125
|
+
slot hiding it.
|
|
126
|
+
|
|
127
|
+
The layers of a stack each cut the slots that pass through them. When they
|
|
128
|
+
differ, as a bench top of `stack = 2` taking the legs' tabs in its lower
|
|
129
|
+
layer and a vice's in its upper one, the stack becomes a part per layer,
|
|
130
|
+
`top, layer 1` and `top, layer 2`, so blind joints don't show through.
|
|
131
|
+
|
|
132
|
+
```kerf
|
|
133
|
+
part("shelf", slots = ["back"]) rect([100, 60]);
|
|
134
|
+
part("back", at = [0, 55, 3], rotate = [75, 0, 0]) {
|
|
135
|
+
rect([100, 60]);
|
|
136
|
+
for (x = [20, 70]) translate([x, -6]) rect([10, 6.01]);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Parts that only touch cut nothing: a wall standing on a shelf without tabs
|
|
141
|
+
leaves it whole.
|
|
142
|
+
|
|
143
|
+
### Bends
|
|
144
|
+
|
|
145
|
+
A living hinge bends a part, and the assembled view can show it bent.
|
|
146
|
+
`bend = [x0, x1, angle]` bends the part along its x between x0 and x1, the
|
|
147
|
+
far end folding up towards its top face by `angle` degrees (down for a
|
|
148
|
+
negative angle); give a list for more than one bend. The hinge's middle
|
|
149
|
+
layer keeps its length, so the radius follows from the hinge's width.
|
|
150
|
+
Parts glued on a bent part take `on = "name"` and move with the run they
|
|
151
|
+
sit on. `flex_strip()` in `kerf/hinge` works out the bends of a strip that
|
|
152
|
+
follows a profile.
|
|
153
|
+
|
|
154
|
+
```kerf
|
|
155
|
+
use <kerf/hinge>
|
|
156
|
+
|
|
157
|
+
// A cover that wraps round a 20 mm spine
|
|
158
|
+
part("cover", bend = [[100, 100 + bend_length(10, 90), 90], [130, 130 + bend_length(10, 90), 90]])
|
|
159
|
+
flex_rect([260, 150], [100 + bend_length(10, 90) / 2, 130 + bend_length(10, 90) / 2], width = bend_length(10, 90));
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The collision check takes each flat run of a bent part on its own.
|
|
163
|
+
|
|
164
|
+
### Numbered parts
|
|
165
|
+
|
|
166
|
+
`$label_parts = true;` numbers the parts 1, 2, 3 in the order they are
|
|
167
|
+
made and engraves each number small on the part's back face, where it has
|
|
168
|
+
the most room, so a buyer can tell alike pieces apart once they are out of
|
|
169
|
+
the sheet. The numbers come in the back job (`design-back.svg`), and
|
|
170
|
+
`kerf check` puts them in the parts list and after each step: `step 2:
|
|
171
|
+
Glue the lock on the front (parts 6, 7, 8)`. JavaScript gets each part's
|
|
172
|
+
`label`. A part with no room for its number warns.
|
|
173
|
+
|
|
174
|
+
### Steps and hardware
|
|
175
|
+
|
|
176
|
+
`step("Glue the sides to the bottom") { ... }` makes an assembly step of
|
|
177
|
+
the parts inside it. The steps keep the order they first run in. The 3D
|
|
178
|
+
view in the playground and on the model pages builds the model a step at
|
|
179
|
+
a time, each step's parts coming down into place. Parts outside any step
|
|
180
|
+
are there from the start.
|
|
181
|
+
|
|
182
|
+
A step inside a step is a sub-step, named after both: a chair module with
|
|
183
|
+
its own `step("Glue the seat")`, placed inside `step("Add the chair")`,
|
|
184
|
+
adds the step "Add the chair: Glue the seat". So a piece of furniture
|
|
185
|
+
builds step by step on its own and inside a room. `step("Add the chair",
|
|
186
|
+
substeps = false)` takes everything inside into the one step instead.
|
|
187
|
+
|
|
188
|
+
`hardware(kind, from, to, size)` lists what else the model needs: a dowel
|
|
189
|
+
from one point to another, a screw, a magnet, a strip of paper. `size` is
|
|
190
|
+
a diameter, or `[w, h]` for a flat piece. `kerf check` lists the hardware
|
|
191
|
+
with the parts, and the 3D view shows it.
|
|
192
|
+
|
|
193
|
+
`shape = "ball"` (or `sides = 0`) makes a ball of diameter `size` midway
|
|
194
|
+
between `from` and `to`, for a light bulb, a marble or a bead. A ball may
|
|
195
|
+
leave `to` out and sit at `from`: `hardware("bulb", [0, 0, 120], size = 60,
|
|
196
|
+
shape = "ball")`.
|
|
197
|
+
|
|
198
|
+
The kinds are these; a colour (`pink`, `yellow`, `red`, `green`, `blue`,
|
|
199
|
+
`orange`, `purple`, `black`, `grey`) works too, and any other kind warns
|
|
200
|
+
and shows grey. JavaScript gets the list as `HARDWARE_KINDS`.
|
|
201
|
+
|
|
202
|
+
| Kind | What it is | Shown |
|
|
203
|
+
| ---------- | ------------------------------------------- | ---------------- |
|
|
204
|
+
| `dowel` | a wooden dowel or axle | matt, #e2c48f |
|
|
205
|
+
| `steel` | a steel rod, pin or axle | metal, #a7adb3 |
|
|
206
|
+
| `brass` | a brass rod, tube or pin | metal, #c9a227 |
|
|
207
|
+
| `screw` | a screw | metal, #9aa0a6 |
|
|
208
|
+
| `bolt` | a bolt | metal, #9aa0a6 |
|
|
209
|
+
| `nut` | a nut | metal, #9aa0a6 |
|
|
210
|
+
| `magnet` | a disc or block magnet | metal, #55585c |
|
|
211
|
+
| `paper` | a sheet or strip of paper | matt, #fbfaf6 |
|
|
212
|
+
| `card` | card stock | matt, #f4f1e8 |
|
|
213
|
+
| `felt` | felt pads or lining | matt, #6f6a64 |
|
|
214
|
+
| `elastic` | an elastic band or cord | matt, #262626 |
|
|
215
|
+
| `cord` | cord, string or thread | matt, #b23a3a |
|
|
216
|
+
| `ribbon` | ribbon or tape | matt, #c2485a |
|
|
217
|
+
| `wire` | wire | metal, #b87333 |
|
|
218
|
+
| `led` | an LED or a strip of them | glowing, #fff4c2 |
|
|
219
|
+
| `bulb` | a light bulb | glowing, #fff4c2 |
|
|
220
|
+
| `ball` | a marble, ball or bead | matt, #8fb8d8 |
|
|
221
|
+
| `tube` | a tube or hollow arbor | metal, #c9a227 |
|
|
222
|
+
| `lens` | a lens | matt, #d6ecf3 |
|
|
223
|
+
| `mirror` | a mirror | metal, #c8d3da |
|
|
224
|
+
| `movement` | a bought clock, music box or motor movement | matt, #3d3d3d |
|
|
225
|
+
| `white` | anything white | matt, #f7f7f4 |
|
|
226
|
+
|
|
227
|
+
```kerf
|
|
228
|
+
step("Stand the walls in the base") {
|
|
229
|
+
part("base", at = [-30, -40, 0]) rect([60, 80]);
|
|
230
|
+
for (y = [-40, 37]) part(str("wall ", y), at = [-30, y + 3, 3], rotate = [90, 0, 0]) rect([60, 40]);
|
|
231
|
+
}
|
|
232
|
+
step("Slide the axle through the walls") hardware("dowel", [0, -45, 25], [0, 45, 25], 6);
|
|
233
|
+
```
|
|
63
234
|
|
|
64
235
|
## Materials
|
|
65
236
|
|
|
@@ -99,6 +270,15 @@ to keep the positions from your code instead of packing the parts.
|
|
|
99
270
|
The CLI `--margin` option and API `margin` option let you set the edge
|
|
100
271
|
spacing separately from the gap between parts.
|
|
101
272
|
|
|
273
|
+
Your laser's bed can be set once for a project: `"sheet": [600, 400]` in the
|
|
274
|
+
project's `kerf.json` is the sheet for every design in it that does not
|
|
275
|
+
set `$sheet`.
|
|
276
|
+
|
|
277
|
+
With `$nest = true` (or `--nest`), small parts go into the holes of bigger
|
|
278
|
+
ones before the rows are packed: the rings of a stacked vase or globe each
|
|
279
|
+
inside the next, washers inside a wheel. A part goes into a hole only
|
|
280
|
+
where its outline, `$gap` all round, fits.
|
|
281
|
+
|
|
102
282
|
## One file per sheet
|
|
103
283
|
|
|
104
284
|
A combined SVG stacks all sheets in one preview. For the material example
|
|
@@ -112,3 +292,21 @@ the matching material settings.
|
|
|
112
292
|
thickness for each sheet.
|
|
113
293
|
|
|
114
294
|
DXF exports contain one sheet per file.
|
|
295
|
+
|
|
296
|
+
## The back face
|
|
297
|
+
|
|
298
|
+
Marks for a part's underside go on `engrave(side = "back")` or
|
|
299
|
+
`score(side = "back")`, drawn where they are on the part seen from the
|
|
300
|
+
top. They are left out of the sheet's file and go into a second job, the
|
|
301
|
+
sheet turned over left to right: `design-back.svg` from the command line,
|
|
302
|
+
`sheet.back` in JavaScript. Cut and engrave the front, turn the whole
|
|
303
|
+
sheet over without moving the parts in it, line it up on the same corner
|
|
304
|
+
and run the back job.
|
|
305
|
+
|
|
306
|
+
```kerf
|
|
307
|
+
part("coaster") {
|
|
308
|
+
circle(d = 90);
|
|
309
|
+
engrave() text("TEA", size = 16, halign = "center", valign = "center");
|
|
310
|
+
engrave(side = "back") text("made for you", size = 6, halign = "center");
|
|
311
|
+
}
|
|
312
|
+
```
|
package/docs/shared-libraries.md
CHANGED
|
@@ -74,7 +74,10 @@ the nearest folder at or above the design's own with a `kerf.json`:
|
|
|
74
74
|
this for its own files, and so do the designs and examples inside it.
|
|
75
75
|
2. `use <name/...>`, where `kerf_libraries/name/` exists: that installed
|
|
76
76
|
library's file.
|
|
77
|
-
3.
|
|
77
|
+
3. An absolute path, as `use </home/me/lib/props>`: that file, wherever
|
|
78
|
+
the design is. Handy for a scratch design outside the project; a
|
|
79
|
+
design to share should use the other forms.
|
|
80
|
+
4. Anything else: a file in the design's folder or below it, as before.
|
|
78
81
|
|
|
79
82
|
Each path is tried as written and with `.kerf` added. A design in
|
|
80
83
|
`projects/shelf/designs/` therefore finds `use <feet/feet>` in
|
|
@@ -139,6 +142,10 @@ project's choice wins:
|
|
|
139
142
|
}
|
|
140
143
|
```
|
|
141
144
|
|
|
145
|
+
A library's own `use <...>` looks next to it first: `lib/props.kerf`
|
|
146
|
+
saying `use <finish.kerf>` finds `lib/finish.kerf`, wherever the design
|
|
147
|
+
that uses `lib/props.kerf` is.
|
|
148
|
+
|
|
142
149
|
## Publish a library
|
|
143
150
|
|
|
144
151
|
A library's top folder holds its `kerf.json`:
|
package/docs/specification.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Specification
|
|
2
2
|
|
|
3
|
-
Language version 0.
|
|
3
|
+
Language version 0.3. Copyright (c) 2026 MyLaserTools. This document is
|
|
4
4
|
licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
|
|
5
5
|
|
|
6
6
|
This document defines KerfScript programs precisely: what text is a
|
|
@@ -11,7 +11,7 @@ differ, this document is the one to fix.
|
|
|
11
11
|
|
|
12
12
|
The [conformance suite](../conformance/README.md) turns these rules into
|
|
13
13
|
small programs with expected results. Each section below names the cases
|
|
14
|
-
that test it. An implementation conforms to language version 0.
|
|
14
|
+
that test it. An implementation conforms to language version 0.3 when it
|
|
15
15
|
passes every case.
|
|
16
16
|
|
|
17
17
|
## Notation
|
|
@@ -41,8 +41,9 @@ ignored.
|
|
|
41
41
|
LINE_COMMENT = "//" { any character except "\n" } ;
|
|
42
42
|
BLOCK_COMMENT = "/*" { any character } "*/" ; (* ends at the first "*/" *)
|
|
43
43
|
|
|
44
|
-
NUMBER = DIGITS [ "." { DIGIT } ] [ EXPONENT ]
|
|
45
|
-
|
|
44
|
+
NUMBER = ( DIGITS [ "." { DIGIT } ] [ EXPONENT ]
|
|
45
|
+
| "." DIGITS [ EXPONENT ] ) [ UNIT ] ;
|
|
46
|
+
UNIT = "mm" | "cm" | "m" | "in" | "ft" ; (* not followed by a LETTER, DIGIT or "_" *)
|
|
46
47
|
EXPONENT = ( "e" | "E" ) [ "+" | "-" ] DIGITS ;
|
|
47
48
|
DIGITS = DIGIT { DIGIT } ;
|
|
48
49
|
|
|
@@ -124,7 +125,9 @@ unary = ( "-" | "+" | "!" ) unary | power ;
|
|
|
124
125
|
power = postfix [ "^" unary ] ;
|
|
125
126
|
postfix = primary { arguments | "[" expr "]" | "." NAME } ;
|
|
126
127
|
primary = NUMBER | STRING | "true" | "false" | "undef" | NAME
|
|
127
|
-
| "(" expr ")" | list ;
|
|
128
|
+
| "(" expr ")" | list | record ;
|
|
129
|
+
record = "{" [ field { "," field } [ "," ] ] "}" ;
|
|
130
|
+
field = NAME "=" expr ;
|
|
128
131
|
|
|
129
132
|
list = "[" "]"
|
|
130
133
|
| "[" expr ":" expr [ ":" expr ] "]"
|
|
@@ -154,6 +157,9 @@ the first choice that fits. Where that needs more than the next token:
|
|
|
154
157
|
on its left: `2 ^ 3 ^ 2` is 512 and `-2 ^ 2` is -4. `?:` nests to the
|
|
155
158
|
right.
|
|
156
159
|
- An `else` belongs to the nearest `if`.
|
|
160
|
+
- A `{` where a value is expected starts a record; where a statement is,
|
|
161
|
+
a block. A record that names a field twice is the error `Field <name> is
|
|
162
|
+
given twice`, at the second.
|
|
157
163
|
|
|
158
164
|
A token that fits no rule is an error: `Expected <what>, found "<token>"`,
|
|
159
165
|
or `found end of file`, at that token.
|
|
@@ -171,6 +177,7 @@ Cases: `values/*`.
|
|
|
171
177
|
| list | ordered sequences of values |
|
|
172
178
|
| range | a start, step and end number; `[a:b]` has step 1 |
|
|
173
179
|
| function | a parameter list, a body expression and the scope the function was made in |
|
|
180
|
+
| record | values by field name, in the order the fields were written (from 0.3) |
|
|
174
181
|
|
|
175
182
|
`type_of(v)` gives the type's name as above. Values cannot be changed
|
|
176
183
|
after they are made; every operation makes a new value.
|
|
@@ -193,6 +200,8 @@ value is true, including `[0]`, `"0"`, ranges and functions.
|
|
|
193
200
|
- both are `undef`,
|
|
194
201
|
- both are lists of the same length whose items are equal in order,
|
|
195
202
|
- both are ranges with the same start, step and end (`[0:2] == [0:1:2]`),
|
|
203
|
+
- both are records with the same field names whose values are equal, in
|
|
204
|
+
any order,
|
|
196
205
|
- or both are the same function value.
|
|
197
206
|
|
|
198
207
|
`a != b` is `!(a == b)`.
|
|
@@ -204,7 +213,8 @@ integer when it is one, and otherwise with up to 10 significant digits
|
|
|
204
213
|
(`1 / 3` is `0.3333333333`, `0.1 + 0.2` is `0.3`). Very large and small
|
|
205
214
|
numbers use exponent form (`1e+21`); infinities are `Infinity` and
|
|
206
215
|
`-Infinity`, NaN is `NaN`, and -0 is `0`. Lists are written as
|
|
207
|
-
`[a, b]`, ranges as `[start:step:end]`,
|
|
216
|
+
`[a, b]`, ranges as `[start:step:end]`, records as `{a = 1, b = "x"}`,
|
|
217
|
+
functions as `function(a, b)` and
|
|
208
218
|
`undef` as `undef`. Strings are written as they are at the top level and in
|
|
209
219
|
double quotes, with escapes, inside a list or after a name. `echo()` writes
|
|
210
220
|
its arguments in the order they are given, a named one as `name = value`.
|
|
@@ -270,21 +280,33 @@ index outside the list, a negative index and an index into any other value
|
|
|
270
280
|
give `undef`.
|
|
271
281
|
|
|
272
282
|
`a.x`, `a.y` and `a.z` are `a[0]`, `a[1]` and `a[2]` on a list.
|
|
273
|
-
`r.begin`, `r.step` and `r.end` read a range.
|
|
274
|
-
`undef
|
|
283
|
+
`r.begin`, `r.step` and `r.end` read a range. On a record, `r.name` and
|
|
284
|
+
`r["name"]` read its field, `undef` when it has none of that name. Any other
|
|
285
|
+
member gives `undef`. `len(r)` counts a record's fields, `keys(r)` lists
|
|
286
|
+
their names in order, and `merge(a, b)` is a record with both's fields,
|
|
287
|
+
`b`'s where both have one. A record is true in a condition.
|
|
275
288
|
|
|
276
289
|
### Calls
|
|
277
290
|
|
|
278
291
|
In `f(args)`, when `f` is a name:
|
|
279
292
|
|
|
280
|
-
1. If a variable named `f` is in scope, its value is
|
|
281
|
-
|
|
293
|
+
1. If a variable named `f` is in scope and holds a function, its value is
|
|
294
|
+
called.
|
|
282
295
|
2. Otherwise a function definition named `f` is called.
|
|
283
296
|
3. Otherwise a built-in function named `f` is called.
|
|
284
|
-
4. Otherwise the error is `
|
|
297
|
+
4. Otherwise, if a variable named `f` is in scope, the error is `"f" is a
|
|
298
|
+
number, not a function` (naming the variable's type).
|
|
299
|
+
5. Otherwise the error is `Unknown function f()`.
|
|
285
300
|
|
|
286
|
-
|
|
287
|
-
|
|
301
|
+
So a variable that does not hold a function never hides a function or a
|
|
302
|
+
built-in of the same name: `len = 3; echo(len([1, 2]))` writes 2. (Before
|
|
303
|
+
language version 0.3 any variable hid them.) Calling a value that is not a
|
|
304
|
+
function in any other way is an error: `Can't call a number`.
|
|
305
|
+
|
|
306
|
+
A module or function defined with the name of a built-in hides the
|
|
307
|
+
built-in wherever the definition is visible, and the program warns
|
|
308
|
+
`module rect hides the built-in rect(); rename it to use both`, with its
|
|
309
|
+
line. The standard library's own definitions do not warn.
|
|
288
310
|
|
|
289
311
|
Arguments are evaluated left to right in the caller's scope, then bound to
|
|
290
312
|
parameters:
|
|
@@ -385,7 +407,10 @@ A statement `name(args) children` calls a module:
|
|
|
385
407
|
statement at that position from 0, or those at a list or range of
|
|
386
408
|
positions (a position outside them runs nothing);
|
|
387
409
|
`$children` is the number of child statements that are not assignments
|
|
388
|
-
or definitions.
|
|
410
|
+
or definitions. A child statement run again in the same call, with
|
|
411
|
+
the same special variables, `place()` frame and step, gives the same
|
|
412
|
+
shape and may be reused rather than run again; one that echoes, warns,
|
|
413
|
+
makes parts, hardware or steps is always run again.
|
|
389
414
|
2. Otherwise a built-in module named `name` runs.
|
|
390
415
|
3. Otherwise the error is `Unknown module name().`, with a hint for
|
|
391
416
|
OpenSCAD's `color()` and `square()`.
|
|
@@ -394,6 +419,13 @@ A modifier changes the call: `*` skips it entirely, so its arguments and
|
|
|
394
419
|
children are not evaluated; `#` and `%` move all of its shapes to the
|
|
395
420
|
`guide` layer; `!` has no effect and is accepted for OpenSCAD files.
|
|
396
421
|
|
|
422
|
+
`call(name, ...)` calls the module whose name is the string `name` (the
|
|
423
|
+
first positional argument, or `name = ...`), user-defined or built-in, with
|
|
424
|
+
the remaining arguments and the call's children, as if it were written
|
|
425
|
+
`name(...)`. A `name` that is not a string is the error `call() needs a
|
|
426
|
+
module's name as a string, got <type>`; an unknown name is `Unknown
|
|
427
|
+
module <name>()`. A user module named `call` hides this.
|
|
428
|
+
|
|
397
429
|
### Special variables
|
|
398
430
|
|
|
399
431
|
A name starting with `$` is a special variable. It is looked up through
|
|
@@ -415,9 +447,16 @@ These start with a value:
|
|
|
415
447
|
| `$sheet` | `[600, 400]` |
|
|
416
448
|
| `$gap` | 3 |
|
|
417
449
|
| `$layout` | `"pack"` |
|
|
450
|
+
| `$scale` | 1 |
|
|
418
451
|
|
|
419
452
|
`PI` is an ordinary variable set to π in the outermost scope.
|
|
420
453
|
|
|
454
|
+
A number with a unit (language version 0.3) is a length in the real world:
|
|
455
|
+
its value times 1 for `mm`, 10 for `cm`, 1000 for `m`, 25.4 for `in` and
|
|
456
|
+
304.8 for `ft`, divided by `$scale` where it is evaluated. A `$scale` that
|
|
457
|
+
is not a number more than 0 is the error `$scale must be a number more than
|
|
458
|
+
0`. Cases: `values/units*`.
|
|
459
|
+
|
|
421
460
|
## Libraries
|
|
422
461
|
|
|
423
462
|
Cases: `imports/*`.
|
|
@@ -429,8 +468,13 @@ rest (the `resolve` render option). The command line, the desktop app and
|
|
|
429
468
|
the language server look in the design's project, the nearest folder at or
|
|
430
469
|
above the design's with a `kerf.json`: `<name/...>` is a file of the
|
|
431
470
|
project when `name` is the project's own name, or of the installed library
|
|
432
|
-
in `kerf_libraries/name/`;
|
|
471
|
+
in `kerf_libraries/name/`; an absolute path is that file; any other path
|
|
472
|
+
is a file in the design's folder.
|
|
433
473
|
Each tries `path`, then `path.kerf` ([Shared libraries](shared-libraries.md)).
|
|
474
|
+
From language version 0.3, a `use` or `include` inside a library whose
|
|
475
|
+
path has a folder, as `lib/props`, first asks for the path beside it,
|
|
476
|
+
`lib/` joined with the path (`..` going up a folder), and only when that
|
|
477
|
+
names nothing for the path as written.
|
|
434
478
|
A path that names nothing is the error `Library <path> not found`. Each path is read and parsed once per render.
|
|
435
479
|
|
|
436
480
|
`use <path>` makes the library's modules and functions available in the
|
|
@@ -488,14 +532,15 @@ Errors come from:
|
|
|
488
532
|
- limits. A program from someone else can run in a browser, so these are
|
|
489
533
|
enforced:
|
|
490
534
|
|
|
491
|
-
| Limit
|
|
492
|
-
|
|
|
493
|
-
| Statements, calls and loop steps
|
|
494
|
-
| Nested module calls
|
|
495
|
-
| Nested function calls
|
|
496
|
-
| Items in one list, characters in one string
|
|
497
|
-
| Items in all lists and strings
|
|
498
|
-
| Points in
|
|
535
|
+
| Limit | Default | Message starts with |
|
|
536
|
+
| --------------------------------------------------------- | ---------- | ------------------------------------------ |
|
|
537
|
+
| Statements, calls and loop steps | 5,000,000 | `Stopped after N steps` |
|
|
538
|
+
| Nested module calls | 1,000 | `Recursion too deep in module name()` |
|
|
539
|
+
| Nested function calls | 2,000 | `Recursion too deep in name()` |
|
|
540
|
+
| Items in one list, characters in one string | 1,000,000 | `a list of N items` / `a range of N items` |
|
|
541
|
+
| Items in all lists and strings | 3,000,000 | `The lists and strings hold more than` |
|
|
542
|
+
| Points in one shape a module makes | 2,000,000 | `The shapes have more than` |
|
|
543
|
+
| Points in all shapes made, `children()` not counted again | 20,000,000 | `Making the shapes took more than` |
|
|
499
544
|
|
|
500
545
|
The [JavaScript API](javascript.md#running-untrusted-code) lists every
|
|
501
546
|
limit and how to change it.
|
|
@@ -519,6 +564,16 @@ reference](../LANGUAGE.md#layers) describes layers, parts, materials, kerf
|
|
|
519
564
|
compensation and sheet packing, and lists the built-in modules that make
|
|
520
565
|
shapes. Shapes outside every `part()` form one part named `part`.
|
|
521
566
|
|
|
567
|
+
Parts placed in 3D compose with every enclosing `place()`, outermost first,
|
|
568
|
+
then the part's own `at` and `rotate`, then for `stack = n` a move of k
|
|
569
|
+
thicknesses along the part's z for its k-th layer. A part with `glue` is
|
|
570
|
+
placed on its host's face instead, after every part has run. `step()`
|
|
571
|
+
numbers steps from 1 in the order they first run; a part or hardware
|
|
572
|
+
outside every step has step 0. A `step(text)` run inside another step is
|
|
573
|
+
the step named `outer: text`, where `outer` is the enclosing step's name;
|
|
574
|
+
inside `step(..., substeps = false)` an inner `step()` only runs its
|
|
575
|
+
children, in the outer step. Cases: `parts/*`.
|
|
576
|
+
|
|
522
577
|
## Known differences
|
|
523
578
|
|
|
524
579
|
These are behaviours of KerfScript 0.4 that this specification records as
|