From 86c23b843317c6b78ad4bbbbce67bd96e2f47c3a Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Tue, 19 Nov 2024 18:57:11 +0100 Subject: [PATCH] Add bounds check to utils module --- util/init.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/init.lua b/util/init.lua index 92c590a..64cd615 100644 --- a/util/init.lua +++ b/util/init.lua @@ -4,4 +4,18 @@ function Util.toHexChar(v) return ("0123456789ABCDEF"):sub(v, v) end +function Util.fromHexChar(c) + local index = ({("0123456789ABCDEF"):find(c)})[1] + if index ~= nil then + return index - 1 + end + return nil +end + +function Util.boundCheck(x, y, w, h) + if x < 1 or x > w or y < 1 or y > h then + error(("Index out of range: (%d %d) is not within ([1,%d], [1,%d])"):format(x, y, w, h)) + end +end + return Util \ No newline at end of file