forked from pyrex/chameleonic
implement fake sprintf
this spends extra tokens to handle "invalid format character" to catch using a % where %% is intended. this is designed to grow with further format chars if needed; I have ideas for not-exactly-POSIX %d, %x, %h, %!, %#, %c, and possibly others but there is absolutely no reason to spend tokens on these things until we need them. (that said, existing debugging output might benefit from some of these other formats, but that debug code is commented out, so maybe nevert.)
This commit is contained in:
parent
aefdfeb99c
commit
b0bca27239
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user