Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local module = {}
- function module.findDupeInTable(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local seen = {}
- local memory = {}
- local hasseenarray = false
- local returnStatus = false
- for i , key in pairs(T) do
- if (seen[key] ~= nil) or (typeof(key) == "table" and hasseenarray == true) then
- module.insert(memory,key)
- continue
- end
- if typeof(key) == "table" then
- hasseenarray = true
- end
- seen[key] = true
- end
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.findDupeInTableWithFilter(T : "Table" , filter : string) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(filter) == "string","Second argument expected to receive string, got "..typeof(filter).." instead")
- local seen = {}
- local memory = {}
- local hasseenarray = false
- local returnStatus = false
- for i , key in pairs(T) do
- local keytype = typeof(key)
- if keytype == filter then continue end
- if (seen[key] ~= nil) or (typeof(key) == "table" and hasseenarray == true) then
- module.insert(memory,key)
- continue
- end
- if typeof(key) == "table" then
- hasseenarray = true
- end
- seen[key] = true
- end
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.findDupeInTableWithFilterList(T : "Table" , filterList : "table : {|type : string|}") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(filterList) == "table","Second argument expected to receive table, got "..typeof(filterList).." instead")
- local seen = {}
- local memory = {}
- local hasseenarray = false
- local returnStatus = false
- for i , key in pairs(T) do
- local keytype = typeof(key)
- local noneedtocheck = module.find(filterList,keytype)
- if noneedtocheck then continue end
- if (seen[key] ~= nil) or (typeof(key) == "table" and hasseenarray == true) then
- module.insert(memory,key)
- continue
- end
- if typeof(key) == "table" then
- hasseenarray = true
- end
- seen[key] = true
- end
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.sort(T : "Table")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T) .. " instead")
- local memory = {}
- module.foreach(T,function(i,key)
- local keytype = typeof(key)
- if keytype == "number" then
- module.movekey(T,memory,i,true)
- end
- end)
- table.sort(memory)
- module.insertByTable(T,memory)
- end
- function module.concat(T : "Table", Seperate : "string", Start : "number?", End : "number?") : string
- assert(typeof(T) == "table", "First argument expected to receive table, got "..typeof(T) .. " instead")
- Start = Start or 1
- End = End or module.getn(T)
- Seperate = Seperate or ""
- local concated = nil
- local success, errorM = pcall(function()
- concated = table.concat(T,Seperate,Start,End)
- end)
- if not errorM then
- errorM = ""
- end
- assert(success == true,"Error : failed to concat whole table, table must have contain illegal value. Error message generated from roblox : "..errorM)
- return concated
- end
- function module.create(times : "number" , newValue : any , insertTo : "table?") : "return table if insertTo argument were given"
- assert(times ~= nil and newValue ~= nil, "Error : Failed to create table, argument missing")
- assert(newValue ~= nil, "Error : Did you forget put argument 2? or argument 2 is nil or invalid")
- assert(times ~= nil,"Error : Did you forget argument 1? or argument 1 is nil or invalid")
- assert(typeof(times) == "number", "Error : argument 1 given must be number, got "..typeof(times).." instead")
- assert(times > 0, "Error : argument 1 must be more then 0, cannot be 0 or negative number")
- insertTo = insertTo or nil
- if insertTo then
- assert(typeof(insertTo) == "table","Error : argument 3 must be table, got "..typeof(insertTo).." instead")
- end
- local t = table.create(times,newValue)
- if insertTo then
- local memory = {}
- local success, message = pcall(function()
- module.foreach(t,function(i,key)
- module.insert(memory,key)
- end)
- end)
- if not message then
- message = ""
- end
- assert(success == true, "Error : Failed to insert table, Error message generated from roblox : "..message)
- local success, message = pcall(function()
- module.foreach(memory,function(i,key)
- module.insert(insertTo,key)
- end)
- end)
- if not message then
- message = ""
- end
- assert(success == true, "Error : An error occured while module in inserting value into table[argument 3], Error message generated from roblox : "..message)
- return "Created table has been inserted to another table, this message is suppose to be 'nil' but module script has returned this message instead of getting nil in the output"
- else
- return t
- end
- end
- function module.clone(T : "Table") : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- return table.clone(T)
- end
- function module.find(T : "Table", needle : "Varient", init : "number?") : number
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(needle ~= nil,"Second arguement expected to received proper argument, got "..typeof(needle).." instead")
- init = init or nil
- if init then
- assert(typeof(init) == "number" and init > 0, "Thrid argument expected to received number and number must more than 0")
- end
- return table.find(T,needle,init)
- end
- function module.freeze(T : "Table") : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- if module.isfrozen(T) then
- warn("table is already frozen, returning table")
- return T
- else
- return table.freeze(T)
- end
- end
- function module.isfrozen(T : "Table") : boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- if table.isfrozen(T) then
- return true
- else
- return false
- end
- end
- function module.deepFreeze(T : "Table") : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- if not module.isfrozen(T) then
- module.freeze(T)
- end
- module.foreach(T,function(i,key)
- if typeof(key) == "table" then
- if not module.isfrozen(key) then
- module.freeze(key)
- end
- end
- end)
- return T
- end
- function module.getn(T : "table") : number
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- return table.getn(T)
- end
- function module.filterByType(T : "Table" ,typeName : string) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeName ~= nil or "", "Second argument expected to receive proper string argument, got "..typeName.." or empty string")
- local memory = {}
- local boolean = false
- module.foreach(T,function(i,key)
- if typeof(key) == typeName then
- module.insert(memory,key)
- end
- end)
- if module.getn(memory) > 0 then
- boolean = true
- end
- return memory, boolean
- end
- function module.filterByTypeWithTable(T : "table", typeName : "table : { | string | }") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typeName) == "table","Second argument expected to receive table, got "..typeof(typeName).." instead")
- local memory = {}
- local boolean = false
- module.foreach(T,function(i,key)
- module.foreach(typeName,function(ii,typeRequired)
- if typeof(key) == typeRequired then
- module.insert(memory,key)
- end
- end)
- end)
- if module.getn(memory) then
- boolean = true
- end
- return memory, boolean
- end
- function module.filterByName(T : "Table", name : string) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(name ~= nil or "", "Second argument expected to receive proper string argument, got empty string or "..typeof(name))
- local memory = {}
- local boolean = false
- module.foreach(T,function(i,key)
- if typeof(key) == "string" and key == name then
- module.insert(memory,key)
- end
- end)
- if module.getn(memory) > 0 then
- boolean = true
- end
- return memory, boolean
- end
- function module.insert(T : "Table" , key : any)
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(key ~= nil,"Argument 2 expected to received proper argument, got ".. typeof(key) .. " instead")
- table.insert(T,key)
- end
- function module.insertByTable(T : "Table" , tableKey : "Table")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(tableKey) == "table","Argument 2 is expected to received table, got ".. typeof(tableKey) .. " instead")
- module.foreach(tableKey,function(i,key)
- module.insert(T,key)
- end)
- end
- function module.clear(T : "Table")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- table.clear(T)
- end
- function module.removeByTable(T : "Table", list : "Table")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
- module.foreach(list,function(i,key)
- module.remove(T,module.find(T,key))
- end)
- end
- function module.remove(T : "Table", target : number)
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(target) == "number","Second argument expected to receive number, got "..typeof(target).." instead")
- table.remove(T,target)
- end
- function module.foreach(T : " Table", callback : "function")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(callback) == "function","Second argument expected to receive uncalled-function, got "..typeof(callback).." instead")
- table.foreach(T,callback)
- end
- function module.foreachi(T : " Table", callback : "function")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(callback) == "function","Second argument expected to receive uncalled-function, got "..typeof(callback).." instead")
- table.foreachi(T,callback)
- end
- function module.pack(... : any) : " (...) -> table"
- return table.pack(...)
- end
- function module.unpack(T : "Table" , i : number , j : number) : "{ | any | } -> tuple"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- i = i or 1
- j = j or nil
- assert(typeof(i) == "number", "Second argument expected to receive number, got "..typeof(i).. " instead")
- if typeof(j) ~= "number" then
- if not j == nil then
- error("Thrid argument can be nil or number, got "..typeof(j).." instead")
- end
- end
- return table.unpack(T,i,j)
- end
- function module.setDictionary(T : "Table", key : any, value : any)
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(key ~= nil,"Second argument expected to receive proper argument, got "..typeof(key).." instead")
- assert(value ~= nil,"Thrid argument expected to receive proper argument, got "..typeof(value).." instead")
- local success, message = pcall(function()
- T[key] = value
- end)
- if not message then
- message = ""
- end
- assert(success == true, "Failed to set dictionary, error message generated from roblox : "..message)
- end
- function module.getDictionary(T : "Table", key : any) : any
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(key ~= nil,"Second argument expected to receive proper argument, got "..typeof(key).." instead")
- local returnValue = nil
- local success, message = pcall(function()
- returnValue = T[key]
- end)
- if not message then
- message = ""
- end
- assert(success == true, "Failed to return dictionary, error message generated from roblox : "..message)
- return returnValue
- end
- function module.move(T1 : "Table1", f : "number", e : "number", t : "number" ,T2 : "Table2") : "Table2"
- assert(typeof(T1) == "table" and typeof(T2) == "table" , "argument 1 and argument 5 are expected to receive table, argument 1 got ".. typeof(T1) .. " and argument 2 got ".. typeof(T2))
- assert(typeof(f) == "number" , "argument 1 must be number, got "..typeof(f).." instead")
- assert(typeof(e) == "number" , "argument 2 must be number, got "..typeof(e).." instead")
- assert(typeof(t) == "number" , "argument 3 must be number, got "..typeof(t).." instead")
- local returnTable = nil
- local success, message = pcall(function()
- returnTable = table.move(
- T1,
- f,
- e,
- t,
- T2
- )
- end)
- if not message then
- message = ""
- end
- assert(success == true , "An error occured when moving key to another key, error message generated from roblox : "..message)
- return returnTable
- end
- function module.maxn(T : "Table") : number
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- return table.maxn(T)
- end
- function module.selectRandom(T : "Table" , rolltime : "number?" , seed : "number?" ) : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- rolltime = rolltime or 100
- assert(typeof(rolltime) == "number","Second argument expected to receive number, got"..typeof(rolltime).. " instead")
- seed = seed or math.random(0,tick())
- local random = Random.new(seed)
- local chosen = nil
- local last = nil
- local function roll()
- chosen = math.floor(random:NextNumber(1,module.getn(T)))
- end
- for i = 0,rolltime,1 do
- roll()
- last = chosen
- end
- return T[chosen]
- end
- function module.findKeyWhichIsAType(T : "Table", typeName : string) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typeName) == "string","Second argument expected to receive string, got "..typeof(T).." instead")
- assert(typeName ~= "", "Second argument were expected to receive string but the string is empty")
- local memory = {}
- local status = false
- module.foreach(T,function(i,key)
- if typeof(key) == typeName then
- module.insert(memory,key)
- end
- end)
- if module.getn(memory) > 0 then
- status = true
- end
- return memory , status
- end
- function module.findKeyWhichIsInTableType(T : "Table" , typeTable : "table : { | type : string | }") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typeTable) == "table","Second argument expected to receive table with string inside, got "..typeof(typeTable).." instead")
- local memory = {}
- local status = false
- module.foreach(T,function(i,key)
- module.foreach(typeTable,function(ii,typename)
- if typeof(key) == typename then
- module.insert(memory,key)
- end
- end)
- end)
- if module.getn(memory) > 0 then
- status = true
- end
- return memory , status
- end
- function module.clearType(T : "Table" , typeName : string)
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typeName) == "string","Second argument expected to receive string, got "..typeof(T).." instead")
- assert(typeName ~= "", "Second argument were expected to receive string but the string is empty")
- local found, didfound = module.findKeyWhichIsAType(T,typeName)
- if found and didfound then
- module.remove(T,found)
- end
- end
- function module.clearTypeWithTable(T : "Table", typeInTable : "{ | type : string | }")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typeInTable) == "table","Second argument expected to receive table, got "..typeof(typeInTable).." instead")
- local found, didfound = module.findKeyWhichIsInTableType(T,typeInTable)
- if found and didfound then
- module.removeByTable(T,found)
- end
- end
- function module.selectMultipleByRandom(T : "Table", times : number, rolltime : "number?", seed : "number?") : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(times) == "number","Second argument expected to receive number, got "..typeof(times).." instead")
- rolltime = rolltime or 100
- assert(typeof(rolltime) == "number","Thrid argument expected to receive number, got "..typeof(rolltime).." instead")
- local chosen = nil
- local last = nil
- seed = seed or math.random(0,tick())
- local returnT = {}
- local random = Random.new(seed)
- local function Roll()
- chosen = T[math.floor(random:NextNumber(1,module.getn(T)))]
- end
- for i = 1,times,1 do
- for i = 0,rolltime,1 do
- Roll()
- last = chosen
- end
- module.insert(returnT,chosen)
- end
- return returnT
- end
- function module.movekey(fromT1 : "Table" , fromT2 : "Table" , n : number , removekeyfromT1 : "boolean?")
- assert(typeof(fromT1) == "table" and typeof(fromT2) == "table" , "First and second argument expected to receive table, first argument got "..typeof(fromT1).." and second argument got "..typeof(fromT2))
- assert(typeof(n) == "number" and n > 0 , "Thrid argument expected to receive number more than 0")
- removekeyfromT1 = removekeyfromT1 or false
- assert(typeof(removekeyfromT1) == "boolean" ,"forth argument expected to receive boolean, got "..typeof(removekeyfromT1).." instead")
- local key = fromT1[n]
- module.insert(fromT2,key)
- if removekeyfromT1 then
- module.remove(fromT1,n)
- end
- end
- function module.clearExcept(T : "Table" , list : "Table")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
- local memory = {}
- module.foreach(T,function(i,key)
- module.foreach(list,function(ii,listkey)
- local found = module.find(T,listkey)
- if found then
- local real_key = T[found]
- if real_key then
- module.movekey(T,memory,found,true)
- end
- end
- end)
- end)
- module.clear(T)
- module.insertByTable(T,memory)
- end
- function module.clearExceptType(T : "Table" , typename : string)
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typename) == "string" , "Second argument expected to receive string, got "..typeof(typename).." instead")
- local memory = {}
- local typeFound , didfound = module.findKeyWhichIsAType(T,typename)
- if typeFound and didfound then
- module.insertByTable(memory,typeFound)
- end
- module.clear(T)
- module.insertByTable(T,memory)
- end
- function module.clearExceptTypeWithTable(T : "Table" , typeTable : "{ |type : string| }")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(typeTable) == "table","Second argument expected to receive table, got "..typeof(typeTable).." instead")
- local memory = {}
- local typeFound , didfound = module.findKeyWhichIsInTableType(T,typeTable)
- if typeFound and didfound then
- module.insertByTable(memory,typeFound)
- end
- module.clear(T)
- module.insertByTable(T,memory)
- end
- function module.getallinstance(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local returnStatus = false
- local typeFound , didfound = module.findKeyWhichIsAType(T,"Instance")
- if typeFound and didfound then
- returnStatus = true
- end
- return typeFound , returnStatus
- end
- function module.getallnumber(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local returnStatus = false
- local typeFound , didfound = module.findKeyWhichIsAType(T,"number")
- if typeFound and didfound then
- returnStatus = true
- end
- return typeFound , returnStatus
- end
- function module.getallboolean(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local returnStatus = false
- local typeFound , didfound = module.findKeyWhichIsAType(T,"boolean")
- if typeFound and didfound then
- returnStatus = true
- end
- return typeFound , returnStatus
- end
- function module.getallstring(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local returnStatus = false
- local typeFound , didfound = module.findKeyWhichIsAType(T,"string")
- if typeFound and didfound then
- returnStatus = true
- end
- return typeFound , returnStatus
- end
- function module.getallarray(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local returnStatus = false
- local typeFound , didfound = module.findKeyWhichIsAType(T,"table")
- if typeFound and didfound then
- returnStatus = true
- end
- return typeFound , returnStatus
- end
- function module.getallnumberthatisunderthen(T : "Table" , min : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(min) == "number","Second argument expected to receive number, got "..typeof(min).." instead")
- local returnStatus = false
- local memory = {}
- local typefound , didfound = module.findKeyWhichIsAType(T,"number")
- if typefound and didfound then
- module.insertByTable(memory,typefound)
- end
- module.foreach(memory,function(i,key)
- if typeof(key) == "number" then
- if key >= min then
- module.remove(memory,i)
- end
- end
- end)
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.getallnumberthatismorethen(T : "Table" , min : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(min) == "number","Second argument expected to receive number, got "..typeof(min).." instead")
- local returnStatus = false
- local memory = {}
- local typefound , didfound = module.findKeyWhichIsAType(T,"number")
- if typefound and didfound then
- module.insertByTable(memory,typefound)
- end
- module.foreach(memory,function(i,key)
- if typeof(key) == "number" then
- if key <= min then
- module.remove(memory,i)
- end
- end
- end)
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.getallnumberthatissameas(T : "Table" , n : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- local returnStatus = false
- local memory = {}
- local typefound , didfound = module.findKeyWhichIsAType(T,"number")
- module.foreach(typefound,function(i,key)
- if typeof(key) == "number" and key >= n and key <= n then
- module.insert(memory,key)
- end
- end)
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.getallstringiflettermorethen(T : "Table" , n : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- local returnStatus = false
- local memory = {}
- local typefound , didfound = module.getallstring(T)
- module.foreach(typefound,function(i,key)
- if typeof(key) == "string" then
- local splited = string.len(key)
- if splited > n then
- module.insert(memory,key)
- end
- end
- end)
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.getallstringifletterunderthen(T : "Table" , n : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- local returnStatus = false
- local memory = {}
- local typefound , didfound = module.getallstring(T)
- module.foreach(typefound,function(i,key)
- if typeof(key) == "string" then
- local splited = string.len(key)
- if splited < n then
- module.insert(memory,key)
- end
- end
- end)
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.getallstringiflettersameas(T : "Table" , n : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- local returnStatus = false
- local memory = {}
- local typefound , didfound = module.getallstring(T)
- module.foreach(typefound,function(i,key)
- if typeof(key) == "string" then
- local splited = string.len(key)
- if splited >= n and splited <= n then
- module.insert(memory,key)
- end
- end
- end)
- if module.getn(memory) > 0 then
- returnStatus = true
- end
- return memory , returnStatus
- end
- function module.getalluncalledfunction(T : "Table") : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local returnStatus = false
- local typefound , didfound = module.findKeyWhichIsAType(T,"function")
- if module.getn(typefound) > 0 then
- returnStatus = true
- end
- return typefound , returnStatus
- end
- function module.callfunction(T : "Table" , n : number) : any
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- return T[n]()
- end
- function module.callfunctionwithwait(T : "Table" , n : number , delayTime : number) : any
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- assert(typeof(delayTime) == "number","Thrid argument expected to receive number, got"..typeof(delayTime).." instead")
- task.wait(delayTime)
- return T[n]()
- end
- function module.callallfunction(T : "Table")
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local typefound , didfound = module.findKeyWhichIsAType(T,"function")
- module.foreach(typefound,function(i,key)
- if typeof(key) == "function" then
- module.callfunction(typefound,i)
- end
- end)
- end
- function module.callallfunctionwithwait(T : "Table" , n : number)
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got"..typeof(n).." instead")
- local typefound , didfound = module.findKeyWhichIsAType(T,"function")
- for i , key in pairs(typefound) do
- module.callfunctionwithwait(typefound,i,n)
- end
- end
- function module.callmultiplefunction(T : "Table" , list : "Table : {number}") : any
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
- local typefound , didfound = module.findKeyWhichIsAType(T,"function")
- module.foreach(list,function(i,n)
- module.callfunction(T,n)
- end)
- end
- function module.callmultiplefunctionwithwait(T : "Table" , list : "Table : {number}", delays : number) : any
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(list) == "table","Second argument expected to receive table, got "..typeof(list).." instead")
- assert(typeof(delays) == "number","Thrid argument expected to receive number, got"..typeof(delays).." instead")
- local typefound , didfound = module.findKeyWhichIsAType(T,"function")
- for i , key in pairs(typefound) do
- module.callfunctionwithwait(typefound,i,delays)
- end
- end
- function module.getalltypesintable(T : "Table") : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- local memory = {}
- module.foreach(T,function(i,key)
- module.insert(memory,typeof(key))
- end)
- return memory
- end
- function module.getalltypesintablewithfilter(T : "Table" , filtername : string) : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(filtername) == "string","Second argument expected to receive string, got"..typeof(filtername).." instead")
- local memory = {}
- module.foreach(T,function(i,key)
- local keytype = typeof(key)
- if keytype ~= filtername then
- module.insert(memory,keytype)
- end
- end)
- return memory
- end
- function module.getalltypesintablewithfilterlist(T : "Table" , filterlist : "table : { |type : string| }") : "Table"
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(filterlist) == "table","Second argument expected to receive table, got"..typeof(filterlist).." instead")
- local memory = {}
- module.foreach(T,function(i,key)
- local keytype = typeof(key)
- local isblacklisted = module.find(filterlist,keytype)
- if not isblacklisted then
- module.insert(memory,keytype)
- end
- end)
- return memory
- end
- function module.limitindex(T : "Table" , n : number) : "Table" | boolean
- assert(typeof(T) == "table","First argument expected to receive table, got "..typeof(T).." instead")
- assert(typeof(n) == "number","Second argument expected to receive number, got "..typeof(n).." instead")
- local totalI = module.getn(T)
- local status = false
- local memory = {}
- if totalI > n then
- local removeN = (totalI - n)
- for i = 1,removeN,1 do
- module.insert(memory,T[i])
- end
- end
- if module.getn(memory) > 0 then
- status = true
- end
- return memory , status
- end
- return module
Add Comment
Please, Sign In to add comment