From 0474f5a0ee34ff77aec8bc294edbe2b9826436d1 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 30 May 2021 16:17:19 +0100 Subject: [PATCH] wea.table_filter: also pass i as the 2nd argument --- worldeditadditions/utils/tables.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/worldeditadditions/utils/tables.lua b/worldeditadditions/utils/tables.lua index a68c9ea..42272f2 100644 --- a/worldeditadditions/utils/tables.lua +++ b/worldeditadditions/utils/tables.lua @@ -83,13 +83,16 @@ end --- Filters the items in the given table using the given function. -- The function is executed for each item in the list. If it returns true, the -- item is kept. If it returns false, the item is discarded. +-- Arguments passed to the function: item, i +-- ...where item is the item to filter, and i is the index in the table the item +-- is located at. -- @param tbl table The table of values to filter. --- @param func function:bool The filter function to execute - should return a boolean value indicating whether the item provided as the first argument should be kept +-- @param func function:bool The filter function to execute - should return a boolean value indicating whether the item provided as the first argument should be kept -- @returns table A new table containing the values that the given function returned true for. function worldeditadditions.table_filter(tbl, func) local result = {} for i,value in ipairs(tbl) do - if func(value) then + if func(value, i) then table.insert(result, value) end end