Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SB-version of the API Dump Parser, as used on http://wiki.roblox.com
- -- Credits for the actual parser go to Anaminus
- -- Credits to einsteinK for editing the parser, and implementing it on the wiki
- -- Credits to einsteinK for quickly making this into a single script
- -- Note: Unlike the wiki, which fetches the api dump from a wiki page, this script
- -- fetches the api dump from Anaminus' site: anaminus.github.io (Thanks for that)
- -- how to match various names
- local mC = '[%w_<> ]*[%w_<>]' -- class name
- local mM = '[%w_ ]*[%w_]' -- member name
- local mT = '[%w_]+' -- value type
- local mE = '[%w_ ]*[%w_]' -- enum item name
- -- Parses an item's tags (stuff in square brackets)
- local function ParseTags(item,tags)
- local tagSet = {}
- for tag in tags:gmatch("%[(.-)%]") do
- tagSet[tag] = true
- end
- item.tags = tagSet
- end
- -- Parses comma-separated arguments
- local function ParseArguments(out,data)
- if #data > 2 then
- for arg in data:sub(2,-2):gmatch("[^,]+") do -- make this better
- local type,name,default
- = arg:match("^ ?("..mT..") (%w+)(.*)$")
- if #default > 0 then
- default = default:match("^ = (.*)$")
- else
- default = nil
- end
- out[#out+1] = {
- Type = type;
- Name = name;
- Default = default;
- }
- end
- end
- end
- local ParseItem = {
- Class = function(data)
- local className,superClass,tags
- = data:match("^("..mC..") : ("..mC..")(.*)$")
- if not className then
- className,tags = data:match("^("..mC..")(.*)$")
- end
- local item = {
- Name = className;
- Superclass = superClass;
- Subclasses = {};
- Properties = {};
- Functions = {};
- YieldFunctions = {};
- Callbacks = {};
- Events = {};
- }
- ParseTags(item,tags)
- return item
- end;
- Property = function(data)
- local valueType,className,memberName,tags
- = data:match("^("..mT..") ("..mC..")%.("..mM..")(.*)$")
- local item = {
- Class = className;
- Name = memberName;
- ValueType = valueType;
- }
- ParseTags(item,tags)
- return item
- end;
- Function = function(data)
- local returnType,className,memberName,argumentData,tags
- = data:match("^("..mT..") ("..mC..")%:("..mM..")(%b())(.*)$")
- local item = {
- Class = className;
- Name = memberName;
- ReturnType = returnType;
- Arguments = {};
- }
- ParseArguments(item.Arguments,argumentData)
- ParseTags(item,tags)
- return item
- end;
- Event = function(data)
- local className,memberName,argData,tags
- = data:match("^("..mC..")%.("..mM..")(%b())(.*)$")
- local item = {
- Class = className;
- Name = memberName;
- Arguments = {};
- }
- ParseArguments(item.Arguments,argData)
- ParseTags(item,tags)
- return item
- end;
- Callback = function(data)
- local returnType,className,memberName,argData,tags
- = data:match("^("..mT..") ("..mC..")%.("..mM..")(%b())(.*)$")
- local item = {
- Class = className;
- Name = memberName;
- ReturnType = returnType;
- Arguments = {};
- }
- ParseArguments(item.Arguments,argData)
- ParseTags(item,tags)
- return item
- end;
- YieldFunction = function(data)
- local returnType,className,memberName,argumentData,tags
- = data:match("^("..mT..") ("..mC..")%:("..mM..")(%b())(.*)$")
- local item = {
- Class = className;
- Name = memberName;
- ReturnType = returnType;
- Arguments = {};
- }
- ParseArguments(item.Arguments,argumentData)
- ParseTags(item,tags)
- return item
- end;
- Enum = function(data)
- local enumName,tags
- = data:match("^("..mC..")(.*)$")
- local item = {
- Name = enumName;
- Items = {};
- }
- ParseTags(item,tags)
- return item
- end;
- EnumItem = function(data)
- local enumName,itemName,itemValue,tags
- = data:match("^("..mC..")%.("..mE..") : (%d+)(.*)$")
- local item = {
- Enum = enumName;
- Name = itemName;
- Value = tonumber(itemValue) or itemValue;
- }
- ParseTags(item,tags)
- return item
- end;
- }
- -- Parse API Dump, line by line
- function Parse(source)
- local database = {}
- local classes = {}
- local properties = {}
- local events = {}
- local callbacks = {}
- local functions = {}
- local yfunctions = {}
- local enums = {}
- local enumitems = {}
- local nLine = 0
- for line in source:gmatch("[^\r\n]+") do
- nLine = nLine + 1
- local type,data = line:match("^\t*(%w+) (.+)$")
- local parser = ParseItem[type]
- if parser then
- local item,err = parser(data)
- if item then
- item.type = type
- database[#database+1] = item
- if type == "Class" then
- classes[item.Name] = item
- elseif type == "Function" then
- functions[item.Name] = item
- elseif type == "YieldFunction" then
- yfunctions[item.Name] = item
- elseif type == "Callback" then
- callbacks[item.Name] = item
- elseif type == "Event" then
- events[item.Name] = item
- elseif type == "Property" then
- properties[item.Name] = item
- elseif type == "Enum" then
- enums[item.Name] = item
- elseif type == "EnumItem" then
- enumitems[item.Name] = item
- end
- else
- print("error parsing line "..nLine..": "..err)
- end
- else
- print("unsupported item type `"..tostring(type).."` on line "..nLine)
- end
- end
- for k,v in pairs(classes) do
- local parent = classes[v.Superclass]
- if parent then
- parent.Subclasses[k] = v
- end
- end
- for a,b in pairs({Functions=functions,YieldFunctions=yfunctions,Events=events,Properties=properties,Callbacks=callbacks}) do
- for k,v in pairs(b) do
- local parent = classes[v.Class]
- if parent then
- parent[a][k] = v
- end
- end
- end
- for k,v in pairs(enumitems) do
- local parent = enums[v.Enum]
- if parent then
- parent.Items[k] = v
- end
- end
- return {
- Classes=classes;
- Enums=enums;
- EnumItems=enumitems;
- Functions=functions;
- YieldFunctions=yfunctions;
- Events=events;
- Properties=properties;
- Callbacks=callbacks;
- }
- end
- local u = "https://github.com/Anaminus/anaminus.github.io/raw/master/rbx/raw/api/latest.txt"
- local ad = Parse(game:GetService("HttpService"):GetAsync(u))
- shared.AD,_G.AD = ad,ad
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement