Skip to content

Commit 9ba8ef6

Browse files
committed
$include
1 parent 15532dc commit 9ba8ef6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

docs/New Features/Preprocessing.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ $alias seq = "a" \
9898
print(seq) --> abc
9999
```
100100

101+
## `$include`
102+
103+
To reuse code for Pluto's parse-time features such as type hinting, you can include a common 'header' file.
104+
105+
```pluto norun title="header.pluto"
106+
$declare _VERSION: string
107+
$declare _PVERSION: string
108+
```
109+
110+
```pluto title="index.pluto" run="https://pluto-lang.org/web/#file_names[]=index.pluto&file_contents[]=%24include%20%22header.pluto%22%0A%0Alocal%20_%3A%20number%20%3D%20_VERSION%20--%20type%20mismatch&file_names[]=header.pluto&file_contents[]=%24declare%20_VERSION%3A%20string%0A%24declare%20_PVERSION%3A%20string"
111+
$include "header.pluto"
112+
113+
local _: number = _VERSION -- type mismatch
114+
```
115+
101116
## `$haltcompiler`
102117

103118
This statement will stop the parser processing further code.

static/custom.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ function patchCodeblocks() {
1616
const button = document.createElement("button");
1717
button.textContent = "Try It";
1818
button.onclick = () => {
19-
window.open("https://pluto-lang.org/web/#code=" + encodeURIComponent([...code.querySelectorAll(".code-container .line")].map(x => x.textContent).join("\n")));
19+
if (code.hasAttribute("run")) {
20+
// Link override for $include
21+
window.open(code.getAttribute("run"));
22+
} else {
23+
window.open("https://pluto-lang.org/web/#code=" + encodeURIComponent([...code.querySelectorAll(".code-container .line")].map(x => x.textContent).join("\n")));
24+
}
2025
};
2126
div.appendChild(button);
2227
}

0 commit comments

Comments
 (0)