From 96da4a7cbdf6b866ef1f12925d002952b931d29a Mon Sep 17 00:00:00 2001 From: NullBite Date: Sun, 20 Mar 2022 22:27:49 -0400 Subject: [PATCH] Add function to merge two tables --- script.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/script.lua b/script.lua index f2b0c6f..49047cd 100644 --- a/script.lua +++ b/script.lua @@ -77,6 +77,25 @@ function filter(func, table) return t end end + +--- Merge two tables. First table value takes precedence when conflict occurs. +---@param tb1 table +---@param tb2 table +function mergeTable(tb1, tb2) + local t={} + for k, v in pairs(tb1) do + t[k]=v + end + for k, v in pairs(tb2) do + if type(k)=="number" then + table.insert(t, v) + else + if t[k]~=nil then + t[k]=v + end + end + end +end -- }}} -- local state variables (do not access within pings) --