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