-
Notifications
You must be signed in to change notification settings - Fork 1
/
resource_init.lua
66 lines (50 loc) · 1.33 KB
/
resource_init.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
return function(chunk)
local addMetaData = AddMetaData
setmetatable(_G, {
__index = function(t, k)
local raw = rawget(t, k)
if raw then
return raw
end
return function(value)
local newK = k
if type(value) == 'table' then
-- remove any 's' at the end (client_scripts, ...)
if k:sub(-1) == 's' then
newK = k:sub(1, -2)
end
if newK == 'server_script' then
addMetaData(newK, 'protection.lua')
for _, v in ipairs(value) do
if v ~= 'protection.lua' then
addMetaData(newK, v)
end
end
else
-- add metadata for each table entry
for _, v in ipairs(value) do
addMetaData(newK, v)
end
end
else
if k == 'server_script' then
addMetaData(k, 'protection.lua')
if value ~= 'protection.lua' then
addMetaData(k, value)
end
else
addMetaData(k, value)
end
end
-- for compatibility with legacy things
return function(v2)
addMetaData(newK .. '_extra', json.encode(v2))
end
end
end
})
-- execute the chunk
chunk()
-- and reset the metatable
setmetatable(_G, nil)
end