WIP: sprintf #21

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

View File

@ -39,14 +39,13 @@ function cycle(tbl,period)
end
-- fake sprintf function
-- %% for literal "%"
-- %~ for literal "%"
-- %v for param
function sprintf(fmt, ...)
function fmt(f, ...)
local out, i = "", 1
for s in all(split(fmt,"%")) do
for s in all(split(f,"%")) do
local m = s[1]
if m == "%" then
if m == "~" then
out ..= "%"
else
local p = select(i,...)
@ -56,6 +55,7 @@ function sprintf(fmt, ...)
else
out ..= "(?!:"..m..":"..tostr(p)..")"
end
end
out ..=sub(s,2)
end
return out