This snippet could solve the problem. It also reduce string.gsub calls
to one per format.
function format(format, args)
-- naive testing whether args is an indexed table. any better solution?
if args[1] ~= nil then
-- args is not an indexed table, we expect the format $1,$2..$100
-- i is the captured number as a string
format = format:gsub("$(%d+)", function(i) return
args[tonumber(i)] end)
else
--
format = format:gsub("$({[^}]-})", args)
-- another solution, to get rid of args["{key}"] and use
args["key"] instead
--format = format:gsub("${([^}]-)}", args)
end
end
--
Gruß Jörg
--
To unsubscribe, send mail to [email protected].