Advertisement
jordan83221

Extra Lua Table Functions

Sep 20th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. setfenv(1,{print=print,setmetatable=setmetatable,type=type,getmetatable=getmetatable})
  2. local table={
  3.     sub=function(tab,a,b)
  4.         local g={}
  5.         for i=a,b do
  6.             if tab[a] and tab[b] then
  7.                 table.insert(g,i)
  8.             end
  9.         end
  10.         return g
  11.     end,
  12.     concat=function(tab)
  13.         local new=""
  14.         for i=1,#tab do
  15.             new=new..tab[i]
  16.         end
  17.         return new
  18.     end,
  19.     meta=function(tab,tab2)
  20.         if tab and tab2 then
  21.             setmetatable(tab,tab2)
  22.         end
  23.     end,
  24.     insert=function(tab,val)
  25.         tab[#tab+1]=val
  26.     end,
  27.     remove=function(tab,val)
  28.         if type(val)~="number" then
  29.             for _,v in next,tab do
  30.                 if v==val then
  31.                     tab[_]=nil
  32.                 end
  33.             end
  34.         else
  35.             tab[val]=nil
  36.         end
  37.     end,
  38.     find=function(tab,val)
  39.         if tab then
  40.             for _,v in next,tab do
  41.                 if v==val then
  42.                     return true
  43.                 else
  44.                     return false
  45.                 end
  46.             end
  47.         end
  48.     end,
  49.     removeStrings=function(tab)
  50.         for i=1,#tab do
  51.             if type(tab[i])=="string" then
  52.                 tab[i]=nil
  53.             end
  54.         end
  55.     end,
  56.     removeNums=function(tab)
  57.         for i=1,#tab do
  58.             if type(tab[i])=="number" then
  59.                 tab[i]=nil
  60.             end
  61.         end
  62.     end,
  63.     wipe=function(tab)
  64.         for i=1,#tab do
  65.             tab[i]=nil
  66.         end
  67.     end
  68. }
  69. table.link=function(tab1,tab2)
  70.     local g={}
  71.     for i=1,#tab1 do
  72.         table.insert(g,tab1[i])
  73.     end
  74.     for i=1,#tab2 do
  75.         table.insert(g,tab2[i])
  76.     end
  77.     return g
  78. end
  79. table.copy=function(tab)
  80.     local g={}
  81.     for i=1,#tab do
  82.         table.insert(g,tab[i])
  83.     end
  84.     return g
  85. end
  86. table.cut=function(tab)
  87.     local g={}
  88.     for i=1,#tab do
  89.         table.insert(g,tab[i])
  90.         table.remove(tab,i)
  91.     end
  92.     return g
  93. end
  94. table.display=function(tab)
  95.     for i=1,#tab do
  96.         print(tab[i])
  97.     end
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement