-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbuild_exported.lua
169 lines (134 loc) · 3.85 KB
/
build_exported.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
-- copy this script to gmod
-- lua_openscript_cl build_exported.lua
-- lua_openscript build_exported.lua
-- copy data/cl_exported.lua to this script's directory
-- copy data/sv_exported.lua to this script's directory
local exported = {}
exported.functions = {}
exported.globals = {}
exported.meta = {}
exported.enums = {}
-- enums
for key, val in pairs(_G) do
if isnumber(val) or isbool(val) then
exported.enums[key] = val
elseif istable(val) then
local everything_number = true
for _, val in pairs(val) do
if not isnumber(val) then
everything_number = false
break
end
end
if everything_number then exported.enums[key] = val end
end
end
local whitelist = {
[_G.Material] = true,
[FindMetaTable("Player").ConCommand] = true,
}
local blacklist = {}
if CLIENT then
whitelist[vgui.Create] = true
whitelist[FindMetaTable("Panel").SetFGColor] = true
whitelist[FindMetaTable("Panel").SetBGColor] = true
blacklist[vgui.CreateX] = true
blacklist[FindMetaTable("Panel").SetFGColorEx] = true
blacklist[FindMetaTable("Panel").SetBGColorEx] = true
end
local function get_func_type(func)
if blacklist[func] then return end
if whitelist[func] or debug.getinfo(func).source == "=[C]" then return "C" end
return "L"
end
local blacklist = {
_M = true,
_NAME = true,
_PACKAGE = true,
SpawniconGenFunctions = true,
}
-- functions
for key, val in pairs(_G) do
if key == "_G" then goto _continue end
if isfunction(val) then
exported.globals[key] = get_func_type(val)
elseif istable(val) and not blacklist[key] then
for func_name, func in pairs(val) do
if not blacklist[func_name] then
if isfunction(func) then
local func_type = get_func_type(func)
if func then
exported.functions[key] = exported.functions[key] or {}
exported.functions[key][func_name] = func_type
end
else
--print("unexpected value in library " .. key .. ": ", func_name, func)
end
end
end
end
::_continue::
end
local blacklist = {
__index = true,
__gc = true,
MetaID = true,
MetaName = true,
MetaBaseClass = true,
}
-- meta
for key, val in pairs(debug.getregistry()) do
if istable(val) and val.MetaID and val.MetaName then
exported.meta[val.MetaName] = {}
for func_name, func in pairs(val) do
if not blacklist[func_name] then
if isfunction(func) then
local func_type = get_func_type(func)
if func then exported.meta[val.MetaName][func_name] = func_type end
else
--print("unexpected value in metatable " .. val.MetaName .. ": ", func_name, func)
end
end
end
end
end
local output = "return {\n"
output = output .. "\tenums = {\n"
for k, v in pairs(exported.enums) do
if isnumber(v) or isbool(v) then
output = output .. "\t\t" .. k .. " = " .. tostring(v) .. ",\n"
else
output = output .. "\t\t" .. k .. " = {\n"
for k, v in pairs(v) do
output = output .. "\t\t\t[\"" .. k .. "\"] = " .. v .. ",\n"
end
output = output .. "\t\t},\n"
end
end
output = output .. "\t},\n"
output = output .. "\tmeta = {\n"
for meta_name, functions in pairs(exported.meta) do
output = output .. "\t\t" .. meta_name .. " = {\n"
for name, type in pairs(functions) do
output = output .. "\t\t\t" .. name .. " = \"" .. type .. "\",\n"
end
output = output .. "\t\t},\n"
end
output = output .. "\t},\n"
output = output .. "\tfunctions = {\n"
for lib_name, functions in pairs(exported.functions) do
output = output .. "\t\t" .. lib_name .. " = {\n"
for name, type in pairs(functions) do
output = output .. "\t\t\t" .. name .. " = \"" .. type .. "\",\n"
end
output = output .. "\t\t},\n"
end
output = output .. "\t},\n"
output = output .. "\tglobals = {\n"
for name, type in pairs(exported.globals) do
output = output .. "\t\t\t" .. name .. " = \"" .. type .. "\",\n"
end
output = output .. "\t},\n"
output = output .. "}\n"
CompileString(output, "test")
file.Write((SERVER and "sv_" or "cl_") .. "exported.txt", output)