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