Advertisement
Bolodefchoco_LUAXML

[Table] table.merge

Sep 4th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.54 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 03/09/2017
  3. --Last update: 03/09/2017
  4. --[[ Notes:
  5.     Does:
  6.         Funde duas tabelas
  7.     Args:
  8.         this -> A tabela a ser fundida
  9.         src -> Tabela principal, base para a fundição
  10. ]]--
  11.  
  12. table.turnTable = function(x)
  13.     return (type(x)=="table" and x or {x})
  14. end
  15. table.merge = function(this,src)
  16.     for k,v in next,src do
  17.         if this[k] then
  18.             if type(v) == "table" then
  19.                 this[k] = table.turnTable(this[k])
  20.                 table.merge(this[k],v)
  21.             else
  22.                 this[k] = this[k] or v
  23.             end
  24.         else
  25.             this[k] = v
  26.         end
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement