Repository navigation
Expand file tree
/
Copy pathBuild.lua
More file actions
145 lines (106 loc) · 3.35 KB
/
Copy pathBuild.lua
File metadata and controls
145 lines (106 loc) · 3.35 KB
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
local Json = require("json")
local ApiDumpFile = "RobloxApiDump.json"
local DataTypesFile = "RobloxDataTypes.json"
local Output = "ReplicatedStorage/RobloxApiDump.lua"
local ApiDumpFilePtr = assert(io.open(ApiDumpFile, "r"))
local Content = ApiDumpFilePtr:read("*a")
ApiDumpFilePtr:close()
local ApiDump = Json.decode(Content)
local DataTypesFilePtr = assert(io.open(DataTypesFile, "r"))
local DataTypesContent = DataTypesFilePtr:read("*a")
DataTypesFilePtr:close()
local DataTypes = Json.decode(DataTypesContent)
local OutputFile = assert(io.open(Output, "w"))
local function WriteType(OutputFile, Type)
OutputFile:write(string.format("{ Category = %q, Name = %q }", Type.Category, Type.Name))
end
local function WriteParameters(OutputFile, Parameters)
OutputFile:write("{")
for Index, Parameter in ipairs(Parameters or {}) do
if Index > 1 then
OutputFile:write(",")
end
OutputFile:write(string.format("{ Name = %q, Type = ", Parameter.Name))
WriteType(OutputFile, Parameter.Type)
OutputFile:write(" }")
end
OutputFile:write("}")
end
local function HasTag(Tags, Target)
for _, Tag in ipairs(Tags or {}) do
if Tag == Target then
return true
end
end
return false
end
local function WriteValue(File, Value)
local ValueType = type(Value)
if ValueType == "nil" then
File:write("nil")
elseif ValueType == "string" then
File:write(string.format("%q", Value))
elseif ValueType == "number" or ValueType == "boolean" then
File:write(tostring(Value))
elseif ValueType == "table" then
File:write("{")
local First = true
for Key, Child in pairs(Value) do
if not First then
File:write(",")
end
First = false
if type(Key) == "string" then
File:write("[" .. string.format("%q", Key) .. "] = ")
else
File:write("[" .. tostring(Key) .. "] = ")
end
WriteValue(File, Child)
end
File:write("}")
else
error("Unsupported value type: " .. ValueType)
end
end
OutputFile:write("return {\nClasses = {")
for _, Class in ipairs(ApiDump.Classes) do
OutputFile:write(string.format("[%q] = {", Class.Name))
OutputFile:write(string.format("Superclass = %q,", Class.Superclass))
OutputFile:write("Members = {")
for _, Member in ipairs(Class.Members or {}) do
local Tags = Member.Tags or {}
if not HasTag(Tags, "Deprecated") and not HasTag(Tags, "Hidden") then
if Member.MemberType == "Property" then
OutputFile:write(
string.format("{ MemberType = %q, Name = %q, ValueType = ", Member.MemberType, Member.Name)
)
WriteType(OutputFile, Member.ValueType)
OutputFile:write(" },\n")
elseif Member.MemberType == "Function" or Member.MemberType == "Event" then
OutputFile:write(
string.format("{ MemberType = %q, Name = %q, Parameters = ", Member.MemberType, Member.Name)
)
WriteParameters(OutputFile, Member.Parameters)
if Member.ReturnType then
OutputFile:write(", ReturnType = ")
WriteType(OutputFile, Member.ReturnType)
end
OutputFile:write(" },\n")
end
end
end
OutputFile:write("},")
OutputFile:write("Tags = {")
for Index, Tag in ipairs(Class.Tags or {}) do
if type(Tag) ~= "table" then
OutputFile:write(string.format("[%q] = %q,", Index, Tag))
end
end
OutputFile:write("},")
OutputFile:write("},")
end
OutputFile:write("},\nDataTypes = ")
WriteValue(OutputFile, DataTypes)
OutputFile:write("\n}")
OutputFile:close()
print("Generated " .. Output)