garden/util.lua
Hyeonung Baek 340ff8f519 A set of updates
- add object door
- refactor log
- etc
2025-01-04 15:53:45 +09:00

37 lines
539 B
Lua

local m = {}
local function rext(a, i)
i = i - 1
local v = a[i]
if v then
return i, v
end
end
function m.ipairs_rev(a)
return rext, a, (#a + 1)
end
function m.between(x, a, b)
return a <= x and x <= b
end
function m.inside(px, py, x, y, w, h)
return m.between(px, x, x+w) and
m.between(py, y, y+h)
end
function m.add_entity(a, x)
table.insert(a, x)
x.idx = #a
end
function m.del_entity(a, x)
table.remove(a, x)
for i, v in ipairs(a) do
v.idx = i
end
end
return m