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/New Features/Continue Statement.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,6 @@ for i = 1, 10 do
14
14
-- continue jumps here.
15
15
end
16
16
```
17
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=--%20Print%20every%20number%20besides%20five.%0D%0Afor%20i%20%3D%201%2C%2010%20do%0D%0A%20%20%20%20if%20i%20%3D%3D%205%20then%0D%0A%20%20%20%20%20%20%20%20continue%0D%0A%20%20%20%20end%0D%0A%20%20%20%20print(i)%0D%0A%20%20%20%20--%20continue%20jumps%20here.%0D%0Aend)
18
17
19
18
:::caution
20
19
Note, `continue` will skip code. If any code within your loop will determine if the loop continues, make sure `continue` doesn't jump over it.
Copy file name to clipboardExpand all lines: docs/New Features/Default Arguments.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,5 +21,3 @@ end
21
21
write() --> No text provided.
22
22
write("Hello!") --> Hello!
23
23
```
24
-
25
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20function%20write(text%20%3D%20%22No%20text%20provided.%22)%0D%0A%20%20%20%20print(text)%0D%0Aend%0D%0A%0D%0Awrite()%20%20%20%20%20%20%20%20%20--%3E%20%22No%20text%20provided.%22%0D%0Awrite(%22Hello!%22)%20--%3E%20%22Hello!%22)
Copy file name to clipboardExpand all lines: docs/New Features/Lambda Expressions.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,6 @@ local s1 = "123"
12
12
local s2 = s1:gsub(".", |c| -> tonumber(c) + 1)
13
13
print(s2) --> 234
14
14
```
15
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20str%20%3D%20%22123%22%0D%0Alocal%20inc_str%20%3D%20str%3Agsub(%22.%22%2C%20%7Cc%7C%20-%3E%20tonumber(c)%20%2B%201)%0D%0Aprint(inc_str)%20--%20%22234%22)
16
15
17
16
As you can see, they take an expression after the arrow, the result of which is implicitly returned.
Copy file name to clipboardExpand all lines: docs/New Features/Named Arguments.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,6 @@ end
10
10
process_file(file = "hello.txt", version = 2) -- "Processing hello.txt with mode 'r' and version 2"
11
11
```
12
12
13
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20function%20process_file(file%2C%20mode%20%3D%20%22r%22%2C%20version%20%3D%201)%0D%0A%20%20%20%20print(%24%22Processing%20%7Bfile%7D%20with%20mode%20'%7Bmode%7D'%20and%20version%20%7Bversion%7D%22)%0D%0Aend%0D%0Aprocess_file(file%20%3D%20%22hello.txt%22%2C%20version%20%3D%202))
14
-
15
13
Note that this example also makes use of [default arguments](Default%20Arguments.md) and [string interpolation](String%20Interpolation.md).
16
14
17
15
## Mixing arguments
@@ -25,8 +23,6 @@ end
25
23
process_file("hello.txt", version = 2) -- "Processing hello.txt with mode 'r' and version 2"
26
24
```
27
25
28
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20function%20process_file(file%2C%20mode%20%3D%20%22r%22%2C%20version%20%3D%201)%0D%0A%20%20%20%20print(%24%22Processing%20%7Bfile%7D%20with%20mode%20'%7Bmode%7D'%20and%20version%20%7Bversion%7D%22)%0D%0Aend%0D%0Aprocess_file(%22hello.txt%22%2C%20version%20%3D%202))
29
-
30
26
## Limitations
31
27
32
28
This feature is implemented entirely in the parser and therefore only works for local functions at the moment.
Copy file name to clipboardExpand all lines: docs/New Features/Named Varargs.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,5 +23,3 @@ function vfunc(...args)
23
23
end
24
24
vfunc("Hello") --> Hello
25
25
```
26
-
27
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=function%20vfunc(...args)%0D%0A%20%20%20%20for%20args%20as%20arg%20do%0D%0A%20%20%20%20%20%20%20%20print(arg)%0D%0A%20%20%20%20end%0D%0Aend%0D%0Avfunc(%22Hello%22)%20--%20%22Hello%22)
Copy file name to clipboardExpand all lines: docs/New Features/Object-Oriented Programming.md
-12Lines changed: 0 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,6 @@ local t = {
39
39
t.say("Hello") --> Hello
40
40
```
41
41
42
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20t%20%3D%20%7B%0D%0A%20%20%20%20static%20function%20say(msg)%0D%0A%20%20%20%20%20%20%20%20print(msg)%0D%0A%20%20%20%20end%0D%0A%7D%0D%0At.say(%22Hello%22)%20--%20%22Hello%22)
43
-
44
42
## New Operator
45
43
46
44
Pluto adds an easy way to make instances with the `new` operator. This operator will also call the `__construct` method if it exists.
@@ -55,8 +53,6 @@ local john = new Human("John")
55
53
print(john.name) --> John
56
54
```
57
55
58
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20Human%20%3D%20%7B%0D%0A%20%20%20%20function%20__construct(name)%0D%0A%20%20%20%20%20%20%20%20self.name%20%3D%20name%0D%0A%20%20%20%20end%0D%0A%7D%0D%0Alocal%20john%20%3D%20new%20Human(%22John%22)%0D%0Aprint(john.name)%20--%20John)
59
-
60
56
Note that for compatibility with Lua and C API classes, the `new` operator checks for the existence of a static 'new' function. If it exists, `new X(...)` will be identical to `X.new(...)`.
61
57
62
58
## Class Statement
@@ -107,8 +103,6 @@ print(human.age) --> 1
107
103
```
108
104
This also adds a `__parent` field to Human.
109
105
110
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=class%20Entity%0D%0A%20%20%20%20age%20%3D%201%0D%0Aend%0D%0A%0D%0Aclass%20Human%20extends%20Entity%0D%0Aend%0D%0A%0D%0Alocal%20human%20%3D%20new%20Human()%0D%0Aprint(human.age)%20--%201)
111
-
112
106
## Parent Expression
113
107
114
108
The `parent` expression is a shorthand for `self.__parent`, which also supports method call syntax, in which case it's a shorthand for `self.__parent.METHOD(self, ...)`.
@@ -134,8 +128,6 @@ print(human.name) --> John
134
128
135
129
Note that if you have a local variable (or function parameter) called "parent", the `parent` expression will defer to it.
136
130
137
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=class%20Entity%0D%0A%20%20%20%20function%20__construct(name)%0D%0A%20%20%20%20%20%20%20%20self.name%20%3D%20name%0D%0A%20%20%20%20end%0D%0Aend%0D%0A%0D%0Aclass%20Human%20extends%20Entity%0D%0A%20%20%20%20--%20If%20we%20don't%20define%20__construct%2C%20the%20parent-constructor%20would%20be%20called%20automatically.%0D%0A%20%20%20%20--%20However%2C%20if%20we%20overwrite%20it%2C%20we%20can%20use%20parent%3A__construct%20to%20call%20it%20manually.%0D%0A%20%20%20%20function%20__construct(name)%0D%0A%20%20%20%20%20%20%20%20parent%3A__construct(name)%0D%0A%20%20%20%20end%0D%0Aend%0D%0A%0D%0Alocal%20human%20%3D%20new%20Human(%22John%22)%0D%0Aprint(human.name)%20--%20%22John%22)
138
-
139
131
## Private Fields
140
132
141
133
Pluto allows you to specify if a field is 'public' or 'private'. Private fields can only be accessed by the class that defined them.
@@ -161,8 +153,6 @@ print(human:getAge()) -- 42
161
153
print(human.age) -- nil
162
154
```
163
155
164
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=class%20Human%0D%0A%20%20%20%20public%20name%0D%0A%20%20%20%20private%20age%0D%0A%0D%0A%20%20%20%20function%20__construct(name%2C%20age)%0D%0A%20%20%20%20%20%20%20%20self.name%20%3D%20name%0D%0A%20%20%20%20%20%20%20%20self.age%20%3D%20age%0D%0A%20%20%20%20end%0D%0A%0D%0A%20%20%20%20function%20getAge()%0D%0A%20%20%20%20%20%20%20%20return%20self.age%0D%0A%20%20%20%20end%0D%0Aend%0D%0A%0D%0Alocal%20human%20%3D%20new%20Human(%22John%22%2C%2042)%0D%0Aprint(human.name)%20--%20%22John%22%0D%0Aprint(human%3AgetAge())%20--%2042%0D%0Aprint(human.age)%20--%20nil)
165
-
166
156
## Constructor Promotion
167
157
168
158
Because a common task of `__construct` methods is to assign the value of arguments to table fields, Pluto provides a simple syntax to reduce this boilerplate:
@@ -183,8 +173,6 @@ print(human:getAge()) -- 42
183
173
print(human.age) -- nil
184
174
```
185
175
186
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=class%20Human%0D%0A%20%20%20%20function%20__construct(public%20name%2C%20private%20age)%0D%0A%20%20%20%20end%0D%0A%0D%0A%20%20%20%20function%20getAge()%0D%0A%20%20%20%20%20%20%20%20return%20self.age%0D%0A%20%20%20%20end%0D%0Aend%0D%0A%0D%0Alocal%20human%20%3D%20new%20Human(%22John%22%2C%2042)%0D%0Aprint(human.name)%20--%20%22John%22%0D%0Aprint(human%3AgetAge())%20--%2042%0D%0Aprint(human.age)%20--%20nil)
187
-
188
176
## Instanceof Operator
189
177
190
178
The `instanceof` operator can be used to check if a table is a class instance, including inherited classes:
Copy file name to clipboardExpand all lines: docs/New Features/String Indexing.md
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,6 @@ print(str[-1]) -- "d"
11
11
```
12
12
Any character-intensive task — for example, a hash algorithm — will greatly benefit from this.
13
13
14
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20str%20%3D%20%22hello%20world%22%0D%0Aprint(str%5B5%5D)%20--%20%22o%22%0D%0Aprint(str%5B200%5D)%20--%20nil%0D%0Aprint(str%5B-1%5D)%20--%20%22d%22)
15
-
16
14
:::caution
17
15
The bytecode of this feature is not backwards-compatible with Lua.
Copy file name to clipboardExpand all lines: docs/New Features/String Interpolation.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,5 @@ local label = "meaning of life"
14
14
local data = { value = 42 }
15
15
print($"The {label} is {data.value}") --> The meaning of life is 42
16
16
```
17
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20label%20%3D%20%22meaning%20of%20life%22%0D%0Alocal%20data%20%3D%20%7B%20value%20%3D%2042%20%7D%0D%0Aprint(%24%22The%20%7Blabel%7D%20is%20%7Bdata.value%7D%22)%20--%20%22The%20meaning%20of%20life%20is%2042%22)
18
17
19
18
As you can see, you declare a string interpolated by prefixing it with the "$" symbol. Brackets can contain any expression. The result of expressions will be converted to a string as with normal concatenation, although note that Pluto supports [boolean concatenation](../QoL%20Improvements/Boolean%20Concatenation) unlike Lua.
Copy file name to clipboardExpand all lines: docs/New Features/Switch Blocks.md
-6Lines changed: 0 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,8 +68,6 @@ end
68
68
```
69
69
The `default` case can be placed anywhere in the block. It also supports fallthrough, so remember to use `break` if you place it above any cases.
70
70
71
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20value%20%3D%203%0D%0Aswitch%20value%20do%0D%0A%20%20case%201%3A%0D%0A%20%20case%202%3A%0D%0A%20%20case%203%3A%0D%0A%20%20case%204%3A%0D%0A%20%20case%205%3A%0D%0A%20%20%20%20print%20%22Got%201-5.%22%0D%0A%20%20%20%20break%0D%0A%20%20default%3A%0D%0A%20%20%20%20print%20%22Value%20is%20greater%20than%205.%22%0D%0Aend%0D%0A--%20Break%20jumps%20here.)
72
-
73
71
## Case Blocks
74
72
75
73
Any expression can be used for the case condition:
@@ -128,8 +126,6 @@ print(place) --> 1st
128
126
129
127
Note that the case blocks here have their conditions delimited by an arrow (->) instead of a colon (:).
130
128
131
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20place%20%3D%201%0D%0Aplace%20%3D%20switch%20place%20do%0D%0A%20%20%20%20case%201%20-%3E%20%221st%22%0D%0A%20%20%20%20case%202%20-%3E%20%222nd%22%0D%0A%20%20%20%20case%203%20-%3E%20%223rd%22%0D%0A%20%20%20%20default%20-%3E%20%24%22%7Bplace%7Dth%22%0D%0Aend%0D%0Aprint(place))
132
-
133
129
Despite not being able to manually fall through, the shorthand fallthrough syntax still works:
134
130
135
131
```pluto
@@ -146,7 +142,5 @@ print_range(9) --> nil
146
142
147
143
Notice how the `default` case was omitted in this example, so it was implicitly set to `default -> nil`.
148
144
149
-
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20function%20print_range(value)%0D%0A%20%20%20%20print(switch%20value%20do%0D%0A%20%20%20%20%20%20%20%20case%201%2C%202%2C%203%20-%3E%20%221-3%22%0D%0A%20%20%20%20%20%20%20%20case%204%2C%205%2C%206%20-%3E%20%224-6%22%0D%0A%20%20%20%20end)%0D%0Aend%0D%0Aprint_range(1)%20--%3E%20%221-3%22%0D%0Aprint_range(6)%20--%3E%20%224-6%22%0D%0Aprint_range(9)%20--%3E%20nil)
150
-
151
145
## Using Compatibility Mode?
152
146
You may need to use `pluto_switch` instead of `switch`. Alternatively, `pluto_use switch` will enable the keyword independently of environment settings.
Copy file name to clipboardExpand all lines: docs/New Features/Ternary Expressions.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,15 @@
2
2
sidebar_position: 1
3
3
---
4
4
Ternary expressions behave identical as to how they would in C. They introduce no new keywords.
5
-
```pluto title="Old Code"
5
+
```plutonorun title="Old Code"
6
6
local max
7
7
if a > b then
8
8
max = a
9
9
else
10
10
max = b
11
11
end
12
12
```
13
-
```pluto title="New Code"
13
+
```plutonorun title="New Code"
14
14
local max = a > b ? a : b
15
15
```
16
16
#### [Try It Yourself](https://pluto-lang.org/web/#code=local%20a%20%3D%206%0Alocal%20b%20%3D%209%0A%0Alocal%20max%20%3D%20a%20%3E%20b%20%3F%20a%20%3A%20b%0A%0Aprint(max))
0 commit comments