WIP: sprintf #21

Draft
kistaro wants to merge 11 commits from kistaro/chameleonic:sprintf into main
Showing only changes of commit 3516d2855e - Show all commits

View File

@ -44,23 +44,29 @@ end
-- %! for tostring(param) -- %! for tostring(param)
-- which dumps tables -- which dumps tables
function fmt(f, ...) function fmt(f, ...)
local out, i = "", 1 local out, i = "", 0
for s in all(split(f,"%")) do for s in all(split(f,"%")) do
local m = s[1] if i == 0 then
if m == "~" then -- before first format directive
out ..= "%" out ..= s
i = 1
else else
local p = select(i,...) local m = s[1]
i+=1 if m == "~" then
if m == "v" then out ..= "%"
out ..= p
elseif m == "!" then
out ..= tostring(p)
else else
out ..= "(?!:"..m..":"..tostring(p)..")" local p = select(i,...)
i+=1
if m == "v" then
out ..= p
elseif m == "!" then
out ..= tostring(p)
else
out ..= "(?!:"..m..":"..tostring(p)..")"
end
end end
out ..=sub(s,2)
end end
out ..=sub(s,2)
end end
return out return out
end end