Skip to content

Commit 125750a

Browse files
committed
String interpolation now implies tostring
1 parent 7ab96ce commit 125750a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
sidebar_position: 1
33
---
4-
String interpolation is a simple alternative syntax to concatenation.
4+
String interpolation is a simple alternative syntax to concatenation that also implies `tostring`.
55

66
```pluto title="Concatenation"
7-
local label = "meaning of life"
8-
local data = { value = 42 }
9-
print("The " .. label .. " is " .. data.value) --> The meaning of life is 42
7+
local label = { en = "meaning of life" }
8+
local data = nil
9+
print("The " .. label.en .. " is " .. tostring(data)) --> The meaning of life is nil
1010
```
1111

1212
```pluto title="String Interpolation"
13-
local label = "meaning of life"
14-
local data = { value = 42 }
15-
print($"The {label} is {data.value}") --> The meaning of life is 42
13+
local label = { en = "meaning of life" }
14+
local data = nil
15+
print($"The {label.en} is {data}") --> The meaning of life is nil
1616
```
1717

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.
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 passed to `tostring`.

0 commit comments

Comments
 (0)