diff --git a/Libs/DF/definitions.lua b/Libs/DF/definitions.lua index 775ff056..352c6d1a 100644 --- a/Libs/DF/definitions.lua +++ b/Libs/DF/definitions.lua @@ -13,6 +13,7 @@ ---@field setfrompath fun(tbl:table, path:string, value:any) : boolean set the value of a table using a path, e.g. setfrompath(tbl, "a.b.c", 10) is the same as tbl.a.b.c = 10 ---@field dump fun(tbl:table, resultString:string, deep:number) : string dump a table to a string ---@field findsubtable fun(tbl:table, index:number, value:any) : integer|nil find the value passed inside a sub table, return the index of the main table where the sub table with the value found is located +---@field remove fun(tbl:table, value:any) : boolean, number remove all values found inside the array, return true if any value was removed and the amount of values removed ---@class df_language : table ---@field Register fun(addonId:any, languageId:string, gameLanguageOnly:boolean?) : table diff --git a/Libs/DF/fw.lua b/Libs/DF/fw.lua index 75ee9781..e4480a60 100644 --- a/Libs/DF/fw.lua +++ b/Libs/DF/fw.lua @@ -1,6 +1,6 @@ -local dversion = 539 +local dversion = 542 local major, minor = "DetailsFramework-1.0", dversion local DF, oldminor = LibStub:NewLibrary(major, minor) @@ -577,6 +577,25 @@ function DF.table.reverse(t) return new end +---remove a value from an array table +---@param t table +---@param value any +---@return boolean +function DF.table.remove(t, value) + local bRemoved = false + local removedAmount = 0 + + for i = 1, #t do + if (t[i] == value) then + table.remove(t, i) + bRemoved = true + removedAmount = removedAmount + 1 + end + end + + return bRemoved, removedAmount +end + ---copy the values from table2 to table1 overwriting existing values, ignores __index and __newindex, keys pointing to a UIObject are preserved ---@param t1 table ---@param t2 table