Last active
March 18, 2024 22:19
-
-
Save uriid1/2b7823c096b3a697ceab7f40b4ccc54b to your computer and use it in GitHub Desktop.
Lua Format String (fstring)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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