From 17d3d2c38fc5aed27785f00cbc2841327da6d78d Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sat, 23 May 2026 17:28:52 -0400 Subject: [PATCH 1/8] Create draft for format specification --- ...-string-interpolation-format-specifiers.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docs/syntax-string-interpolation-format-specifiers.md diff --git a/docs/syntax-string-interpolation-format-specifiers.md b/docs/syntax-string-interpolation-format-specifiers.md new file mode 100644 index 00000000..77608764 --- /dev/null +++ b/docs/syntax-string-interpolation-format-specifiers.md @@ -0,0 +1,20 @@ +# Format Specification in String Interpolation +## Summary + +## Motivation +Most languages have some form of template strings that easily allow number formatting. Python has f-strings and C has `printf`. Lua has `string.format`, but in terms of readability, string interpolation is superior, but lacks the ability to effectively format floats. +## Design +String interpolation is internally implemented using `string.format` with `%*`. Selecting an additional format specifier should be relatively straightforward. +```luau +local balance = 100.204 +print(`You have ${balance;.02f} in your account.`) +``` +## Drawbacks +String interpolation is no longer safe and can error if the format specifier doesn't match the type. +## Alternatives +Keep on using `string.format` for format specification. +### Delimiters +This RFC was originally denied due to the delimiter. +`,` was denied as it creates a false impression of adding an argument into the interpolated string. Some users might expect a function that returns `2, ".2f"` to use the second parameter as the format specifier. +`:` is used for namecalls. +`;` is already used in Luau to separate statements or to separate indexes. It's never required to be used in Luau, but seems to be the least evil option as the delimiter. \ No newline at end of file From 73c918c012be3db7334fb790c4f00c9409286106 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 02:55:40 -0400 Subject: [PATCH 2/8] Finish up document --- ...-string-interpolation-format-specifiers.md | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/docs/syntax-string-interpolation-format-specifiers.md b/docs/syntax-string-interpolation-format-specifiers.md index 77608764..4ea4378d 100644 --- a/docs/syntax-string-interpolation-format-specifiers.md +++ b/docs/syntax-string-interpolation-format-specifiers.md @@ -1,20 +1,44 @@ -# Format Specification in String Interpolation +# Format Specification for String Interpolation + ## Summary +Allow string interpolation to be able to use all format specifiers supported by `string.format`. It is delimited by `;` in interpolated strings. + ## Motivation -Most languages have some form of template strings that easily allow number formatting. Python has f-strings and C has `printf`. Lua has `string.format`, but in terms of readability, string interpolation is superior, but lacks the ability to effectively format floats. + +Most languages have some form of template strings that easily allow number formatting. Python has f-strings, C has `printf` and C# has native string interpolation with specifiers. Lua has `string.format`, but in terms of readability, string interpolation is superior, but lacks the ability to effectively format floats and integers. + ## Design -String interpolation is internally implemented using `string.format` with `%*`. Selecting an additional format specifier should be relatively straightforward. + +String interpolation is internally implemented using `string.format` with `%*`. Selecting a different format specifier should be relatively straightforward. This will support most future additions to `string.format`. + ```luau -local balance = 100.204 -print(`You have ${balance;.02f} in your account.`) +local balance = 100.2035 +print(`You have ${balance;.2f} in your bank account.`) -- 'You have $100.20 in your bank account.' ``` + +```luau +local digit = 12345 +print(`{digit} is {digit;#x} in hex!`) -- '12345 is 0x3039 in hex!' +``` + +```luau +local score = 1030 +print(`Score: {score;06i}`) -- 'Score: 001030' +``` + ## Drawbacks -String interpolation is no longer safe and can error if the format specifier doesn't match the type. + +String interpolation is no longer safe for primitives and can error if the format specifier does not match the type. + ## Alternatives -Keep on using `string.format` for format specification. + +- Keep on using `string.format` for format specification. This can be achieved by using `string.format` in place of string interpolation or nesting it within one. + ### Delimiters + This RFC was originally denied due to the delimiter. -`,` was denied as it creates a false impression of adding an argument into the interpolated string. Some users might expect a function that returns `2, ".2f"` to use the second parameter as the format specifier. -`:` is used for namecalls. -`;` is already used in Luau to separate statements or to separate indexes. It's never required to be used in Luau, but seems to be the least evil option as the delimiter. \ No newline at end of file + +- `,` was denied as it creates a false impression of adding an argument into the interpolated string. Some users might expect a function that returns `2, ".2f"` to use the second parameter as the format specifier. +- `:` is used for namecalls, and conflating the symbol with string interpolation could cause confusion. +- `;` is already used in Luau to separate statements or to separate keys in dictionaries. It is never required to be used in Luau, but seems to be the least evil option as the delimiter. \ No newline at end of file From 871678be5c65afb4bdc947a95366256efa188c17 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 02:59:38 -0400 Subject: [PATCH 3/8] Fixed name of file --- ...ers.md => syntax-string-interpolation-format-specification.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{syntax-string-interpolation-format-specifiers.md => syntax-string-interpolation-format-specification.md} (100%) diff --git a/docs/syntax-string-interpolation-format-specifiers.md b/docs/syntax-string-interpolation-format-specification.md similarity index 100% rename from docs/syntax-string-interpolation-format-specifiers.md rename to docs/syntax-string-interpolation-format-specification.md From 455e93ef3440583cf7562024884048619ba9db29 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 03:38:13 -0400 Subject: [PATCH 4/8] Covered other alternatives and clarified text --- ...ring-interpolation-format-specification.md | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/syntax-string-interpolation-format-specification.md b/docs/syntax-string-interpolation-format-specification.md index 4ea4378d..fe4125a1 100644 --- a/docs/syntax-string-interpolation-format-specification.md +++ b/docs/syntax-string-interpolation-format-specification.md @@ -10,22 +10,30 @@ Most languages have some form of template strings that easily allow number forma ## Design -String interpolation is internally implemented using `string.format` with `%*`. Selecting a different format specifier should be relatively straightforward. This will support most future additions to `string.format`. +String interpolation is internally implemented using `string.format` with `%*`. Selecting a different format specifier should be relatively straightforward. +Format specifiers must be added after a `;` onto interpolated values. This will support most future additions to `string.format`. + +Some examples: ```luau local balance = 100.2035 -print(`You have ${balance;.2f} in your bank account.`) -- 'You have $100.20 in your bank account.' +print(`You have ${balance;.2f} in your bank account.`) ``` +`You have $100.20 in your bank account.` ```luau local digit = 12345 -print(`{digit} is {digit;#x} in hex!`) -- '12345 is 0x3039 in hex!' +print(`{digit} is {digit;#x} in hex!`) ``` +`12345 is 0x3039 in hex!` ```luau local score = 1030 -print(`Score: {score;06i}`) -- 'Score: 001030' +print(`Score:\ +{score;05i}`) ``` +`Score` +`01030` ## Drawbacks @@ -40,5 +48,10 @@ String interpolation is no longer safe for primitives and can error if the forma This RFC was originally denied due to the delimiter. - `,` was denied as it creates a false impression of adding an argument into the interpolated string. Some users might expect a function that returns `2, ".2f"` to use the second parameter as the format specifier. -- `:` is used for namecalls, and conflating the symbol with string interpolation could cause confusion. -- `;` is already used in Luau to separate statements or to separate keys in dictionaries. It is never required to be used in Luau, but seems to be the least evil option as the delimiter. \ No newline at end of file +- `:` was denied as is used for namecalls, and conflating the symbol with string interpolation could cause confusion. +- `|`, `&`, `#`, `=`, and `@` are all used in the language already. These would clash with how the symbols are already used in the language. +- `!` does not seem like a good choice for Luau as it would introduce a new symbol to normal code when its only use currently is for comment directives. +- `$` is reserved to not be used as a symbol in Luau. +- `;` is already used in Luau to separate statements or to separate keys in dictionaries. It is never required to be used in Luau, and seems to be the least evil option as the delimiter. This feels like an acceptable extension to how `;`s are used today. + +Other alternative delimiters (like `%`) were denied due to issues with backwards compatibility. \ No newline at end of file From 5cd84463f097d612741ef0d503404e36a3b95fa4 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 03:39:20 -0400 Subject: [PATCH 5/8] Fixed newline --- docs/syntax-string-interpolation-format-specification.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax-string-interpolation-format-specification.md b/docs/syntax-string-interpolation-format-specification.md index fe4125a1..f0d953c3 100644 --- a/docs/syntax-string-interpolation-format-specification.md +++ b/docs/syntax-string-interpolation-format-specification.md @@ -32,7 +32,7 @@ local score = 1030 print(`Score:\ {score;05i}`) ``` -`Score` +`Score`\ `01030` ## Drawbacks From fe5c33a963ada31e25fe5fb8cbf60132523de055 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 03:41:36 -0400 Subject: [PATCH 6/8] Further clarified alternatives --- docs/syntax-string-interpolation-format-specification.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/syntax-string-interpolation-format-specification.md b/docs/syntax-string-interpolation-format-specification.md index f0d953c3..f0932412 100644 --- a/docs/syntax-string-interpolation-format-specification.md +++ b/docs/syntax-string-interpolation-format-specification.md @@ -49,9 +49,9 @@ This RFC was originally denied due to the delimiter. - `,` was denied as it creates a false impression of adding an argument into the interpolated string. Some users might expect a function that returns `2, ".2f"` to use the second parameter as the format specifier. - `:` was denied as is used for namecalls, and conflating the symbol with string interpolation could cause confusion. -- `|`, `&`, `#`, `=`, and `@` are all used in the language already. These would clash with how the symbols are already used in the language. -- `!` does not seem like a good choice for Luau as it would introduce a new symbol to normal code when its only use currently is for comment directives. +- `|`, `&`, `#`, `=`, `~`, and `@` are all used in the language already. These would clash with how the symbols are already used in the language. - `$` is reserved to not be used as a symbol in Luau. +- `!` does not seem like a good choice for Luau as it would introduce a new symbol to normal code when its only use currently is for comment directives. This is the second best option. - `;` is already used in Luau to separate statements or to separate keys in dictionaries. It is never required to be used in Luau, and seems to be the least evil option as the delimiter. This feels like an acceptable extension to how `;`s are used today. Other alternative delimiters (like `%`) were denied due to issues with backwards compatibility. \ No newline at end of file From c3ca50082de45f4444856c5140173fa8b5283c39 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 03:48:53 -0400 Subject: [PATCH 7/8] grammar --- docs/syntax-string-interpolation-format-specification.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/syntax-string-interpolation-format-specification.md b/docs/syntax-string-interpolation-format-specification.md index f0932412..aa8bea04 100644 --- a/docs/syntax-string-interpolation-format-specification.md +++ b/docs/syntax-string-interpolation-format-specification.md @@ -52,6 +52,6 @@ This RFC was originally denied due to the delimiter. - `|`, `&`, `#`, `=`, `~`, and `@` are all used in the language already. These would clash with how the symbols are already used in the language. - `$` is reserved to not be used as a symbol in Luau. - `!` does not seem like a good choice for Luau as it would introduce a new symbol to normal code when its only use currently is for comment directives. This is the second best option. -- `;` is already used in Luau to separate statements or to separate keys in dictionaries. It is never required to be used in Luau, and seems to be the least evil option as the delimiter. This feels like an acceptable extension to how `;`s are used today. +- `;` is already used in Luau to separate statements or to separate keys in dictionaries. It is never required to be used in Luau, and seems to be the least evil option as the delimiter. This feels like an acceptable extension to how `;` is used today. -Other alternative delimiters (like `%`) were denied due to issues with backwards compatibility. \ No newline at end of file +Other alternative delimiters (like `%`) were denied due to backwards compatibility. \ No newline at end of file From c24829f3ed2fe188f8d9480c58d5209a2fdfaa87 Mon Sep 17 00:00:00 2001 From: Max Nguyen Date: Sun, 24 May 2026 04:17:48 -0400 Subject: [PATCH 8/8] oops. removed an unnecessary bullet point --- docs/syntax-string-interpolation-format-specification.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax-string-interpolation-format-specification.md b/docs/syntax-string-interpolation-format-specification.md index aa8bea04..8162fa75 100644 --- a/docs/syntax-string-interpolation-format-specification.md +++ b/docs/syntax-string-interpolation-format-specification.md @@ -41,7 +41,7 @@ String interpolation is no longer safe for primitives and can error if the forma ## Alternatives -- Keep on using `string.format` for format specification. This can be achieved by using `string.format` in place of string interpolation or nesting it within one. +Keep on using `string.format` for format specification. This can be achieved by using `string.format` in place of string interpolation or nesting it within one. ### Delimiters