diff --git a/chameleonic.p8 b/chameleonic.p8 index bc9028a..2522e0c 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -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]