Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function validator(args)
- for i = 1, #args do
- if type(args[i]) ~= 'table' then
- return false
- end
- end
- return true
- end
- local function getInputTbls(args, key)
- local inputTbls = {}
- for i=1, #args do
- local nextVal = args[i][key]
- if nextVal and type(nextVal) == 'table' then
- table.insert(inputTbls, nextVal)
- end
- end
- return inputTbls
- end
- local function deepCopy(...)
- local args = {...}
- if not validator(args) then
- return {}
- end
- local newTbl = {}
- for i = #args, 1, -1 do
- for key, val in pairs(args[i]) do
- if not newTbl[key] then
- local inputTbls = getInputTbls(args, key)
- if type(val) == 'table' then
- newTbl[key] = deepCopy(unpack(inputTbls))
- else
- newTbl[key] = val
- end
- end
- end
- end
- return newTbl
- end
- return deepCopy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement