From 271d079bbb56223b560996965a26a32a9d58c089 Mon Sep 17 00:00:00 2001 From: Westerbly Snaydley Date: Sun, 24 Oct 2021 18:32:14 -0500 Subject: [PATCH 1/2] Fix intersect depending on exported mathx --- intersect.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/intersect.lua b/intersect.lua index 18b3a3c..f77d7b5 100644 --- a/intersect.lua +++ b/intersect.lua @@ -17,6 +17,7 @@ local path = (...):gsub("intersect", "") local vec2 = require(path .. "vec2") +local mathx = require(path .. "mathx") --module storage local intersect = {} @@ -337,10 +338,10 @@ function intersect.aabb_aabb_collide(a_pos, a_hs, b_pos, b_hs, into) --actually collided if abs_amount.x <= abs_amount.y then --x min - res = into:scalar_set(abs_amount.x * math.sign(delta.x), 0) + res = into:scalar_set(abs_amount.x * mathx.sign(delta.x), 0) else --y min - res = into:scalar_set(0, abs_amount.y * math.sign(delta.y)) + res = into:scalar_set(0, abs_amount.y * mathx.sign(delta.y)) end end return res From cf8e0ac81a550a8d41e6fee6827e94fce2d1b699 Mon Sep 17 00:00:00 2001 From: Westerbly Snaydley Date: Tue, 9 Nov 2021 23:45:01 -0500 Subject: [PATCH 2/2] add ripairs (reverse ipairs) --- init.lua | 3 +++ tablex.lua | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/init.lua b/init.lua index 2acf119..08d3a1e 100644 --- a/init.lua +++ b/init.lua @@ -78,6 +78,9 @@ function _batteries:export() --overwrite assert wholesale (it's compatible) assert = self.assert + --like ipairs, but in reverse + ripairs = self.tablex.ripairs + --export the whole library to global `batteries` batteries = self diff --git a/tablex.lua b/tablex.lua index eacf80c..82b530b 100644 --- a/tablex.lua +++ b/tablex.lua @@ -417,4 +417,19 @@ function tablex.unpack8(t) return t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8] end +local function iter (t, i) + i = i - 1 + local v = t[i] + if v then + return i, v + end +end + +--iterator that works like ipairs, but in reverse order, +--with keys #t to 1. May prematurely stop at the first nil value +--if the table has gaps. +function tablex.ripairs (t) + return iter, t, #t + 1 +end + return tablex