Skip to content

Commit a3e35e2

Browse files
committed
Remove constexpr attribute, add '$define'
1 parent 1f7ba13 commit a3e35e2

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

docs/New Features/Compile-Time Evaluation.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,29 @@ And on the following functions:
3131
- `tonumber`
3232
- `utonumber`
3333

34+
## Variables
35+
36+
Compile-time constant variables can be defined via the `$define` statement:
37+
```pluto
38+
$define a = 123
39+
```
40+
This may seem identical to a local declared with the const attribute:
41+
```pluto
42+
local a <const> = 123
43+
```
44+
However, `$define` also enforces that the assigned variable is a compile-time constant:
45+
```pluto
46+
local a <const> = {}
47+
// ERROR:
48+
$define a = {} -- variable was not assigned a compile-time constant value
49+
```
50+
3451
## Conditionals
3552

3653
If there is certain code you only want to have compiled in for a certain build, such as a debug build, you can use compile-time conditionals:
3754

3855
```pluto
39-
local DEBUG <constexpr> = true
56+
$define DEBUG = true
4057
4158
$if DEBUG then
4259
print("Script running in debug mode")
@@ -45,4 +62,4 @@ $else
4562
$end
4663
```
4764

48-
In this case, only one of the two paths will be compiled in; the rest will not take up any space. We're also using the [constexpr attribute](<Constexpr Attribute>) here, for stricter guarantees than `<const>`, although `$if` would throw an error if the condition was not known at compile-time.
65+
In this case, only one of the two paths will be compiled in; the rest will not take up any space.

docs/New Features/Constexpr Attribute.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/theme/pluto.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Prism.languages.pluto = {
22
'comment': /^#!.+|--(?:\[(=*)\[[\s\S]*?\]\1\]|.*)/m,
33
'attr-name': /(?<=(function|class|extends)\s)[\w:]+/,
4-
'keyword': /\$|\b(?:and|as|class|pluto_class|enum|begin|break|do|else|elseif|end|for|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|try|catch|pluto_try|pluto_catch)\b/,
4+
'keyword': /\$(define\b)?|\b(?:and|as|class|pluto_class|enum|begin|break|do|else|elseif|end|for|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|try|catch|pluto_try|pluto_catch)\b/,
55
'function': [
66
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!new)\w+(?=\s*(?:\??\())/, // func()
77
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!not)\w+(?=\s*(?:\??[{"]))/, // func "", func {}
@@ -11,7 +11,7 @@ Prism.languages.pluto = {
1111
/\b(os\.platform|json\.null|json\.withnull|json\.withorder)\b/, // standard library constants
1212
/\b(debug|table|string|number|io|os|coroutine|_VERSION|_PVERSION|_PSOUP)\b/, // standard library + type hints
1313
],
14-
'attr-value': /<(const|constexpr|close)>/,
14+
'attr-value': /<(const|close)>/,
1515
'string': {
1616
pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\z(?:\r\n|\s)|\\(?:\r\n|[^z]))*\1|\[(=*)\[[\s\S]*?\]\2\]/,
1717
greedy: true

0 commit comments

Comments
 (0)