love-cellular-automata/util.lua

32 lines
567 B
Lua
Raw Normal View History

2022-09-11 04:23:52 +00:00
function printt(t, prefix, maxdepth)
prefix = prefix or ''
maxdepth = maxdepth or 2
for k, v in pairs(t) do
if prefix ~= '' then
k = prefix .. "." .. k
end
if type(v) == "table" then
if maxdepth > 1 then
print(k .. ":")
printt(v, k, maxdepth - 1)
else
print(k .. ": <table>")
end
else
print(k .. ": " .. tostring(v))
end
end
end
2022-09-11 16:08:09 +00:00
2022-09-12 02:19:31 +00:00
function round2even(num)
return 2 * math.floor(num / 2)
end
2022-09-15 03:05:05 +00:00
function wrap(n, high)
n = n % high
if n < 0 then
n = n + high
end
return n
end