mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Placeholder pages
This commit is contained in:
parent
f763f4c948
commit
a6b5dc74c0
2 changed files with 43 additions and 0 deletions
|
@ -219,3 +219,6 @@ end
|
||||||
```
|
```
|
||||||
|
|
||||||
The default iteration order for tables is specified to be consecutive for elements `1..#t` and unordered after that, visiting every element; similarly to iteration using `pairs`, modifying the table entries for keys other than the current one results in unspecified behavior.
|
The default iteration order for tables is specified to be consecutive for elements `1..#t` and unordered after that, visiting every element; similarly to iteration using `pairs`, modifying the table entries for keys other than the current one results in unspecified behavior.
|
||||||
|
|
||||||
|
## String interpolation
|
||||||
|
|
||||||
|
|
40
docs/_posts/2023-02-02-luau-string-interpolation.md
Normal file
40
docs/_posts/2023-02-02-luau-string-interpolation.md
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
---
|
||||||
|
layout: single
|
||||||
|
title: "String Interpolation"
|
||||||
|
---
|
||||||
|
|
||||||
|
String interpolation is the new syntax introduced to Luau that allows you to create a string literal with expressions inside of that string literal.
|
||||||
|
|
||||||
|
In short, it's a safer and more ergonomic alternative over `string.format`.
|
||||||
|
|
||||||
|
Here's a quick example of a string interpolation:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local combos = {2, 7, 1, 8, 5}
|
||||||
|
print(`The lock combination is {table.concat(combos)}. Again, {table.concat(combos, ", ")}.`)
|
||||||
|
--> The lock combination is 27185. Again, 2, 7, 1, 8, 5.
|
||||||
|
```
|
||||||
|
|
||||||
|
String interpolation also composes well with `__tostring` metamethod.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local balance = setmetatable({ value = 500 }, {
|
||||||
|
__tostring = function(self)
|
||||||
|
return "$" .. tostring(self.value)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
print(`You have {balance}!`)
|
||||||
|
--> You have $500!
|
||||||
|
```
|
||||||
|
|
||||||
|
Known Limitations
|
||||||
|
Script editor will not support auto-formatting string interpolations.
|
||||||
|
|
||||||
|
Luau currently does not define any format specifiers for string interpolations.
|
||||||
|
|
||||||
|
Luau currently does not support any_function_call`with backticks without parentheses`.
|
||||||
|
|
||||||
|
Luau currently does not support backtick string literals as a type annotation, so type Foo = `Foo` is invalid.
|
||||||
|
|
||||||
|
Please post any comments or concerns you may have!
|
Loading…
Add table
Reference in a new issue