A Python-like f-string implementation for Lua.
See https://ezhik.jp/f-string.lua for more information and a playground.
f = require("f-string")
local who = "hedgehogs"
print(f"hello {who}!")You can put any Lua expression into the f-string and it'll hopefully work.
= endings are supported:
> f"{1 + 1 = }"
1 + 1 = 2Formatting specs support everything in string.format and can be used with :%:
> f"{100:%.2f}"
100.00- Upvalue access is kinda broken: Variables from outer scopes of functions (upvalues) are only reliably accessible if they are referenced outside the f-string. For example:
local x = "outer scope"
local function inner()
-- This reference is needed for the upvalue to be accessible in the f-string
if x then end
local result = f"x = {x}" -- Now works correctly
end- Uses
debugso is probably slow as heck
make test