From 0d9cd6fefce079309211c1a0125c3fb206ce2784 Mon Sep 17 00:00:00 2001 From: Xertis <118364459+Xertis@users.noreply.github.com> Date: Thu, 6 Mar 2025 15:54:40 +0300 Subject: [PATCH] table.filter bug fix --- res/scripts/stdmin.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/res/scripts/stdmin.lua b/res/scripts/stdmin.lua index 5ebf0176..ce592277 100644 --- a/res/scripts/stdmin.lua +++ b/res/scripts/stdmin.lua @@ -151,9 +151,27 @@ function table.map(t, func) end function table.filter(t, func) + + for i = #t, 1, -1 do + if not func(i, t[i]) then + table.remove(t, i) + end + end + + local size = #t + for i, v in pairs(t) do - if not func(i, v) then - t[i] = nil + local i_type = type(i) + if i_type == "number" then + if i < 1 or i > size then + if not func(i, v) then + t[i] = nil + end + end + else + if not func(i, v) then + t[i] = nil + end end end