aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutumn <git@autumnfo.rest>2026-05-16 18:36:38 +0100
committerAutumn <git@autumnfo.rest>2026-05-16 18:36:38 +0100
commitfc5f00a9fcfb50e02d7fc447a19e522b5b86f55f (patch)
treec963d0547b04c8d7ef723be500c807f5a70cb7ce
parentf63f463571ac1f181c93d41efef1a834748cfaca (diff)
[util] added string <-> hex utils
-rw-r--r--src/utils.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/utils.lua b/src/utils.lua
new file mode 100644
index 0000000..af6e91f
--- /dev/null
+++ b/src/utils.lua
@@ -0,0 +1,17 @@
+--
+-- ~~~ helper utils
+--
+
+-- string -> hex
+function string.tohex(str)
+ return (str:gsub(".", function (c)
+ return string.format("%02X", string.byte(c))
+ end))
+end
+
+-- hex -> string
+function string.fromhex(str)
+ return (str:gsub("..", function (cc)
+ return string.char(tonumber(cc, 16))
+ end))
+end