-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.lua
71 lines (55 loc) · 1.48 KB
/
table.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- Reminder: This script only works in Luau environment!
-- Renewed table library
-- Functions that were replaced:
-- pack:
-- Old: Packs all the arguments packed, including a "n" field with the number of arguments passed
-- New: Packs all the arguments packed, without the "n" field. Nil values are not permitted
-- find:
-- Old: Finds the argument passed, looping through the numeric keys
-- New: Finds the argument passed, looping through all the keys
-- Functions added:
-- GetDeprecated: Returns a list of functions deprecated for Luau
--!strict
local deprecatedFunctions = {"foreach", "foreachi", "getn"}
local function count(tab: {any}): number
local increment = 0
for i, v in tab do
increment += 1
end
return increment
end
local metatable = {
__len = function(tab)
return count(tab)
end,
}
local renewedTableLibrary = {}
function renewedTableLibrary:GetDeprecated()
return deprecatedFunctions
end
function renewedTableLibrary:AddMetatable(tab: {any})
return setmetatable(tab, metatable)
end
function renewedTableLibrary.pack(...: any)
return {...}
end
function renewedTableLibrary.find<a>(tab: {any}, arg: a): a?
for i, v in tab do
if v == arg then
return v
end
end
return nil
end
function renewedTableLibrary.getn(tab)
return count(tab)
end
function renewedTableLibrary.maxn(tab)
return count(tab)
end
for i, v in table :: {any} do
if not renewedTableLibrary[i] then
renewedTableLibrary[i] = v
end
end
return renewedTableLibrary