mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 17:58:54 +00:00
Renamed arguments
This commit is contained in:
+39
-37
@@ -1,14 +1,16 @@
|
||||
ESX.Table = {}
|
||||
|
||||
-- nil proof alternative to #table
|
||||
function ESX.Table.SizeOf(table)
|
||||
function ESX.Table.SizeOf(t)
|
||||
local keys = {}
|
||||
|
||||
for k,v in pairs(table) do
|
||||
for k,v in pairs(t) do
|
||||
table.insert(keys, tonumber(k))
|
||||
end
|
||||
|
||||
table.sort(keys, function(a,b) return a < b end)
|
||||
table.sort(keys, function(a, b)
|
||||
return a < b
|
||||
end)
|
||||
|
||||
if #keys > 0 then
|
||||
return keys[#keys]
|
||||
@@ -17,9 +19,9 @@ function ESX.Table.SizeOf(table)
|
||||
end
|
||||
end
|
||||
|
||||
function ESX.Table.IndexOf(table, value)
|
||||
for i=1, #table, 1 do
|
||||
if table[i] == value then
|
||||
function ESX.Table.IndexOf(t, value)
|
||||
for i=1, #t, 1 do
|
||||
if t[i] == value then
|
||||
return i
|
||||
end
|
||||
end
|
||||
@@ -27,9 +29,9 @@ function ESX.Table.IndexOf(table, value)
|
||||
return -1
|
||||
end
|
||||
|
||||
function ESX.Table.LastIndexOf(table, value)
|
||||
for i=#table, 1, -1 do
|
||||
if table[i] == value then
|
||||
function ESX.Table.LastIndexOf(t, value)
|
||||
for i=#t, 1, -1 do
|
||||
if t[i] == value then
|
||||
return i
|
||||
end
|
||||
end
|
||||
@@ -37,19 +39,19 @@ function ESX.Table.LastIndexOf(table, value)
|
||||
return -1
|
||||
end
|
||||
|
||||
function ESX.Table.Find(table, cb)
|
||||
for i=1, #table, 1 do
|
||||
if cb(table[i]) then
|
||||
return table[i]
|
||||
function ESX.Table.Find(t, cb)
|
||||
for i=1, #t, 1 do
|
||||
if cb(t[i]) then
|
||||
return t[i]
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
function ESX.Table.FindIndex(table, cb)
|
||||
for i=1, #table, 1 do
|
||||
if cb(table[i]) then
|
||||
function ESX.Table.FindIndex(t, cb)
|
||||
for i=1, #t, 1 do
|
||||
if cb(t[i]) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
@@ -57,45 +59,45 @@ function ESX.Table.FindIndex(table, cb)
|
||||
return -1
|
||||
end
|
||||
|
||||
function ESX.Table.Filter(table, cb)
|
||||
function ESX.Table.Filter(t, cb)
|
||||
local newTable = {}
|
||||
|
||||
for i=1, #table, 1 do
|
||||
if cb(table[i]) then
|
||||
table.insert(newTable, table[i])
|
||||
for i=1, #t, 1 do
|
||||
if cb(t[i]) then
|
||||
table.insert(newTable, t[i])
|
||||
end
|
||||
end
|
||||
|
||||
return newTable
|
||||
end
|
||||
|
||||
function ESX.Table.Map(table, cb)
|
||||
function ESX.Table.Map(t, cb)
|
||||
local newTable = {}
|
||||
|
||||
for i=1, #table, 1 do
|
||||
newTable[i] = cb(table[i], i)
|
||||
for i=1, #t, 1 do
|
||||
newTable[i] = cb(t[i], i)
|
||||
end
|
||||
|
||||
return newTable
|
||||
end
|
||||
|
||||
function ESX.Table.Reverse(table)
|
||||
function ESX.Table.Reverse(t)
|
||||
local newTable = {}
|
||||
|
||||
for i=#table, 1, -1 do
|
||||
table.insert(newTable, table[i])
|
||||
for i=#t, 1, -1 do
|
||||
table.insert(newTable, t[i])
|
||||
end
|
||||
|
||||
return newTable
|
||||
end
|
||||
|
||||
function ESX.Table.Clone(table)
|
||||
if type(table) ~= 'table' then return table end
|
||||
function ESX.Table.Clone(t)
|
||||
if type(t) ~= 'table' then return t end
|
||||
|
||||
local meta = getmetatable(table)
|
||||
local meta = getmetatable(t)
|
||||
local target = {}
|
||||
|
||||
for k,v in pairs(table) do
|
||||
for k,v in pairs(t) do
|
||||
if type(v) == 'table' then
|
||||
target[k] = ESX.Table.Clone(v)
|
||||
else
|
||||
@@ -108,26 +110,26 @@ function ESX.Table.Clone(table)
|
||||
return target
|
||||
end
|
||||
|
||||
function ESX.Table.Concat(table1, table2)
|
||||
local table3 = ESX.Table.Clone(table1)
|
||||
function ESX.Table.Concat(t1, t2)
|
||||
local t3 = ESX.Table.Clone(t1)
|
||||
|
||||
for i=1, #table2, 1 do
|
||||
table.insert(table3, table2[i])
|
||||
for i=1, #t2, 1 do
|
||||
table.insert(t3, t2[i])
|
||||
end
|
||||
|
||||
return t3
|
||||
end
|
||||
|
||||
function ESX.Table.Join(table, sep)
|
||||
function ESX.Table.Join(t, sep)
|
||||
local sep = sep or ','
|
||||
local str = ''
|
||||
|
||||
for i=1, #table, 1 do
|
||||
for i=1, #t, 1 do
|
||||
if i > 1 then
|
||||
str = str .. sep
|
||||
end
|
||||
|
||||
str = str .. table[i]
|
||||
str = str .. t[i]
|
||||
end
|
||||
|
||||
return str
|
||||
|
||||
Reference in New Issue
Block a user