Skip to content

Instantly share code, notes, and snippets.

@uriid1
Last active March 18, 2024 22:19
Show Gist options
  • Save uriid1/2b7823c096b3a697ceab7f40b4ccc54b to your computer and use it in GitHub Desktop.
Save uriid1/2b7823c096b3a697ceab7f40b4ccc54b to your computer and use it in GitHub Desktop.
Lua Format String (fstring)
--- Lua format string
-- @param text text
-- @param args table
local function fstring(text, args)
local res, _ = string.gsub(text, '%${([%w_]+)}', args)
return res
end
-- Example
--[[
local fstring = require('fstring')
string.fstring = fstring
local str = '${name}, hello!'
print(str:fstring({ name = 'uriid1' })) -- Uriid1, hello!
]]
return fstring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment