WIP: sprintf #21

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

View File

@ -41,6 +41,8 @@ end
-- fake sprintf function
-- %~ for literal "%"
-- %v for param
-- %! for tostring(param)
-- which dumps tables
function fmt(f, ...)
local out, i = "", 1
for s in all(split(f,"%")) do
@ -51,9 +53,11 @@ function fmt(f, ...)
local p = select(i,...)
i+=1
if m == "v" then
out ..= select(i,...)
out ..= p
elseif m == "!" then
out ..= tostring(p)
else
out ..= "(?!:"..m..":"..tostr(p)..")"
out ..= "(?!:"..m..":"..tostring(p)..")"
end
end
out ..=sub(s,2)