Skip to content

Commit 7bc44fb

Browse files
Sainanwell-in-that-case
authored andcommitted
Document const statement
1 parent 2563de7 commit 7bc44fb

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

docs/QoL Improvements/Let Alias For Local.md

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Pluto introduces 2 optional shorthands for the `local` statement.
2+
3+
## Let
4+
5+
To enable the `let` keyword, simply do:
6+
```pluto
7+
pluto_use let
8+
```
9+
10+
The usage is exactly the same as the `local` keyword.
11+
12+
However, note that this will make `let` a reserved keyword, so you can't name any variables as such.
13+
If this is causing ambiguities in your script, you can disable it again after you're done with it:
14+
```pluto
15+
pluto_use let = false
16+
```
17+
18+
## Const
19+
20+
To enable the `const` keyword, simply do:
21+
```pluto
22+
pluto_use const
23+
```
24+
25+
This allows you to do the following:
26+
```pluto
27+
const meaning = 42
28+
```
29+
As a shorthand for:
30+
```pluto
31+
local meaning <const> = 42
32+
```
33+
34+
## For Integrators
35+
36+
You can enable `let` and `const` in your Pluto environment by default by defining the `PLUTO_USE_LET` and `PLUTO_USE_CONST` macros in `luaconf.h` or your build config.

src/theme/pluto.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Prism.languages.pluto = {
1313
},
1414
'boolean': /\b(?:true|false)\b/,
1515
'number': /\b([\d][\d_]+|(0x[a-f\d]+)|(0b[01]+))(?:\.[a-f\d]*)?(?:p[+-]?\d+)?\b|\b\d+(?:\.\B|(?:\.\d*)?(?:e[+-]?\d+)?\b)|\B\.\d+(?:e[+-]?\d+)?\b/i,
16-
'keyword': /\$|\b(?:and|as|class|pluto_class|enum|begin|break|do|else|elseif|end|for|function|goto|if|in|local|new|not|or|repeat|return|static|then|until|while|continue|switch|case|default|pluto_switch|pluto_continue|extends|export|pluto_export|pluto_use|public|private)\b/,
16+
'keyword': /\$|\b(?:and|as|class|pluto_class|enum|begin|break|do|else|elseif|end|for|function|goto|if|in|local|new|not|or|repeat|return|static|then|until|while|continue|switch|case|default|pluto_switch|pluto_continue|extends|export|pluto_export|pluto_use|public|private|const)\b/,
1717
'variable': /\b(?:self|parent|pluto_parent)\b/,
1818
'operator': [
1919
/[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?|\:=|\?|(?<!\w)\:|\?\.|instanceof/,

0 commit comments

Comments
 (0)