Untitled

mail@pastecode.io avatar
unknown
lua
2 years ago
1.2 kB
1
Indexable
Never
-- Written by Glory
-- Recreation of Roblox's Table Library
-- 3/11/22

local Table = {}

function Table.clear(tbl)
  for i, _ in ipairs(tbl) do
    tbl[i] = nil
  end
end

function Table.concat(tbl, separator, startindex, endindex)
    local newStr = ""

    for i = startindex or 1, endindex or #tbl do
        local value = tbl[i]
        if value then
            if newStr == "" then
                newStr = value.. separator
            else
                newStr = newStr.. separator.. value
            end
        end
    end

    return newStr
end

function Table.create(count, value)
    local tbl = {}

    for i = 1, count do
        tbl[i] = value
    end
    
    return tbl
end

function Table.find(tbl, value, startpoint)
  for i = startpoint or 1, #tbl do
    if tbl[i] == value then
      return i
    end
  end
  return nil
end

function Table.getn(tbl)
  return #tbl
end

function Table.insert(tbl, value)
  tbl[#tbl + 1] = value
end

function Table.pack(...)
  return {...}
end

function Table.foreach(array, func)
    for i, v in ipairs(array) do
        func(i, v)
    end
end



return Table