From 93c154f8767e0a3a59ef562da8cc6314c236c0d1 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sun, 1 Jan 2023 12:37:11 -0800 Subject: [PATCH] fix sprintf and rename to fmt the "split on %" strategy makes parsing "%%" complicated, so the "actually literally %" placeholder is now "%~" rather than "%%". since thsi resembles a real sprintf even less now I renamed it to "fmt". also actually closes the `if m == "~"` block. (which was `if m == "%"` before this patch) --- chameleonic.p8 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index 2522e0c..cace9a2 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -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