From 91603e21f84974cc62faa82eacb01fb50898cbe1 Mon Sep 17 00:00:00 2001 From: Vanic Date: Fri, 3 Apr 2026 21:43:43 +0300 Subject: [PATCH] `Table`: Replacing the Voxrames version of `table.join` with ours --- mods/SYSTEM/Table/init.lua | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/mods/SYSTEM/Table/init.lua b/mods/SYSTEM/Table/init.lua index bc2f863..cb76072 100644 --- a/mods/SYSTEM/Table/init.lua +++ b/mods/SYSTEM/Table/init.lua @@ -170,34 +170,28 @@ function table.merge(t1, t2, recursively) return result end ----Adds key-value from `table2` into `table1` only if that key does not exists in `table1`. ----Values that are tables are copied by `table.copy()`. ----If `recursively` is true, the function will be applied recursively for values ----that are tables in both `table1` and `table2`. ---- ---- ----@overload fun(t1:table, t2:table):table ---- ----@generic T: table, U: table ----@param t1 T ----@param t2 U ----@param recursively boolean Default: false. Go recursively if both values are tables. ---- ----Original source: [Voxrame](https://github.com/Voxrame/Voxrame/blob/d5255d466ca502267023c146696a655cf09595b3/helpers/src/lua_ext/table.lua#L161) ----@return T|U -function table.join(t1, t2, recursively) - recursively = recursively or false - for key, value in pairs(t2) do - if not t1[key] then - t1[key] = type(value) == 'table' and tableCopy(value) or value - else - if recursively and type(t1[key]) == 'table' and type(value) == 'table' then - table.join(t1[key], value, recursively) - end - end + +--- Appends a second list to the end of the first list, +--- thereby concatenating the two lists together. +--- @generic t +--- @param t1 t[] +--- @param t2 t[] +--- @return t[] +function table.join(t1, t2) + ensureArgType(t1, 'table', 1, 'table.join') + ensureArgType(t2, 'table', 2, 'table.join') + + local result = {} + for i, v in ipairs(t1) do + result[i] = v end - return t1 + local offset = #t1 + for i, v in ipairs(t2) do + result[offset + i] = v + end + + return result end --- Returns an array containing only unique values of the table `t`.