String interpolation - Finally HERE!

If your familiar with python, you might now what f strings are, they look a bit like this:

local Test = "Hi!"

print(f"{Test} How are you today?")

This would output: Hi! How are you today?. Useful right?

Here is a quick quote from the official topic:

Without further ado, we’re happy to release a beta feature for string interpolation! Please note, since this is a beta feature, it will only work in Studio.

String interpolation is the new syntax that allows you to create a string literal with expressions inside of that string literal. You can read about it in the RFC for string interpolation .

In short, it’s a safer and more ergonomic alternative over string.format. Here’s a quick example of a string interpolation:

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.

It looks great, does it?

local balance = setmetatable({ value = 500 }, {
    __tostring = function(self)
        return "$" .. tostring(self.value)

print(`You have {balance}!`)
--> You have $500!

I can’t wait to experiment with this tomorrow and I would highly recommend you check it out for yourself too!

I presume this can be enabled through roblox studio beta but hereare the current limitations:

  1. Script editor will not support auto-formatting string interpolations.

  2. Luau currently does not define any format specifiers for string interpolations.

  3. Luau currently does not support any_function_callwith backticks without parentheses``.

  4. Luau currently does not support backtick string literals as a type annotation, so type Foo = `Foo` is invalid.

Can’t wait to see what is made with this! Enjoy! :partying_face:

1 Like

This is extremely useful, it can get messy to write print(“You now have”..balance..”!”), especially when you need to use multiple variables in one string.


Agreed, or if you have long messages.

Woah, wasn’t sure what was it about but with the example, it seems rlly useful actually-