Added dropboxs

This commit is contained in:
Cooldude2606
2019-08-30 17:13:22 +01:00
parent 38f0413b31
commit a80d0bf99d
98 changed files with 1651 additions and 124 deletions

View File

@@ -619,4 +619,67 @@ function Common.get_file_path(offset)
return debug.getinfo(offset+2, 'S').source:match('^.+/currently%-playing/(.+)$'):sub(1, -5)
end
--[[-- Much faster method for inserting items into an array
@tparam table tbl the table that will have the values added to it
@tparam[opt] number start_index the index at which values will be added, nil means end of the array
@tparam table values the new values that will be added to the table
@treturn table the table that was passed as the first argument
@usage-- Adding 1000 values into the middle of the array
local tbl = {}
local values = {}
for i = 1,1000 do tbl[i] = i values[i] = i end
Common.array_insert(tbl,500,values) -- around 0.4ms
]]
function Common.array_insert(tbl,start_index,values)
if not values then
values = start_index
start_index = nil
end
if start_index then
local starting_length = #tbl
local adding_length = #values
local move_to = start_index+adding_length+1
for offset = 0, starting_length-start_index do
tbl[move_to+offset] = tbl[starting_length+offset]
end
start_index = start_index-1
else
start_index = #tbl
end
for offset, item in ipairs(values) do
tbl[start_index+offset] = item
end
return tbl
end
--[[-- Much faster method for inserting keys into a table
@tparam table tbl the table that will have keys added to it
@tparam[opt] number start_index the index at which values will be added, nil means end of the array, numbered indexs only
@tparam table tbl2 the table that may contain both string and numbered keys
@treturn table the table passed as the first argument
@usage-- Merging two tables
local tbl = {}
local tbl2 = {}
for i = 1,100 do tbl[i] = i tbl['_'..i] = i tbl2[i] = i tbl2['__'..i] = i end
Common.table_insert(tbl,50,tbl2)
]]
function Common.table_insert(tbl,start_index,tbl2)
if not tbl2 then
tbl2 = start_index
start_index = nil
end
Common.array_insert(tbl,start_index,tbl2)
for key, value in pairs(tbl2) do
if not tonumber(key) then
tbl[key] = value
end
end
return tbl
end
return Common