WIP: sprintf #21

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

View File

@ -38,6 +38,29 @@ function cycle(tbl,period)
return tbl[t()%period*#tbl\period+1]
end
-- fake sprintf function
-- %% for literal "%"
-- %v for param
function sprintf(fmt, ...)
local out, i = "", 1
for s in all(split(fmt,"%")) do
local m = s[1]
if m == "%" then
out ..= "%"
else
local p = select(i,...)
i+=1
if m == "v" then
out ..= select(i,...)
else
out ..= "(?!:"..m..":"..tostr(p)..")"
end
out ..=sub(s,2)
end
return out
end
mnames={}
function names(root)
local n=mnames[root]