mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
This allows "%(...)" inside a string literal to interpolate the stringified result of an expression. It doesn't support custom interpolators or format strings, but we can consider extending that later.
18 lines
761 B
Plaintext
18 lines
761 B
Plaintext
class Foo {
|
|
construct new() {}
|
|
[a] { "1-subscript %(a)" }
|
|
[a, b] { "2-subscript %(a) %(b)" }
|
|
[a, b, c] { "3-subscript %(a) %(b) %(c)" }
|
|
[a]=(value) { "1-subscript setter %(a) = %(value)" }
|
|
[a, b]=(value) { "2-subscript setter %(a) %(b) = %(value)" }
|
|
[a, b, c]=(value) { "3-subscript setter %(a) %(b) %(c) = %(value)" }
|
|
}
|
|
|
|
var foo = Foo.new()
|
|
System.print(foo["a"]) // expect: 1-subscript a
|
|
System.print(foo["a", "b"]) // expect: 2-subscript a b
|
|
System.print(foo["a", "b", "c"]) // expect: 3-subscript a b c
|
|
System.print(foo["a"] = "value") // expect: 1-subscript setter a = value
|
|
System.print(foo["a", "b"] = "value") // expect: 2-subscript setter a b = value
|
|
System.print(foo["a", "b", "c"] = "value") // expect: 3-subscript setter a b c = value
|