summaryrefslogtreecommitdiff
path: root/src/util.lua
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-19 15:23:06 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-19 15:23:06 -0600
commitda9dd31f504d30f33922cdf362a7c01673a6b927 (patch)
tree6e3247dc8f57c16fd02d7ac07246d82c8ab65ccb /src/util.lua
parent90ee66a3a6aae10fd84f3f43844db55229933e37 (diff)
downloadggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.gz
ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.tar.bz2
ggj25-da9dd31f504d30f33922cdf362a7c01673a6b927.zip
Last commit before theme release
Diffstat (limited to 'src/util.lua')
-rw-r--r--src/util.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util.lua b/src/util.lua
index 52597b2..f0192dc 100644
--- a/src/util.lua
+++ b/src/util.lua
@@ -90,4 +90,16 @@ function util.reverse(tbl, val)
return ret
end
+function util.typecheck(tbl, ...)
+ local args = {...}
+ assert(#args % 2 == 0,"Typecheck should have an odd number of arguments, found " .. tostring(#args + 1) .. ".")
+ for i = 1, #args, 2 do
+ assert(args[i] and type(args[i]) == "string", "Cannot check a field of type " .. type(args[i]) .. " at position " .. tostring(i + 1) .. ".")
+ assert(tbl[args[i]], "Failed to find a field: " .. args[i])
+ assert(args[i+1] and type(args[i + 1]) == "string", "Cannot check for a type " .. type(args[i + 1]) .. " at position " .. tostring(i + 2) .. ".")
+ assert(type(tbl[args[i]]) == args[i+1], "Expected a " .. args[i+1] .. " at position " .. tostring(i+2) .. " but found a " .. type(tbl[args[i]]))
+ end
+ return true
+end
+
return util