Module:ReflectionMetadataHelpers

local reflectionmetadata = mw.loadData('Module:ReflectionMetadata').data

local p = {}

--% This function returns the item. --: (table) the item with information about classes, or nil if not found function p.get_classes for _, item in ipairs(reflectionmetadata.roblox.Item) do       if item._attr.class == "ReflectionMetadataClasses" then return item end end end

--% This function returns the item. --: (table) the item with information about enums, or nil if not found function p.get_enums for _, item in ipairs(reflectionmetadata.roblox.Item) do       if item._attr.class == "ReflectionMetadataEnums" then return item end end end

--% This function returns the item for a class. --@ class_name (string) the name of the class --: (table) the item with information about the class, or nil if not found function p.get_class_data(class_name) for _, item in ipairs(p.get_classes.Item) do       if item._attr.class == "ReflectionMetadataClass" then for _, property in ipairs(item.Properties.string) do               if property._attr and property._attr.name and property._attr.name == "Name" then if property[1] == class_name then return item end break end end end end end

--% This function returns the item for an enum. --@ enum_name (string) the name of the enum --: (table) the item with information about the enum, or nil if not found function p.get_enum_data(enum_name) for _, item in ipairs(p.get_enums.Item) do       if item._attr.class == "ReflectionMetadataEnum" then for _, property in ipairs(item.Properties.string) do               if property._attr and property._attr.name and property._attr.name == "Name" then if property[1] == enum_name then return item end break end end end end end

--% This function gets a class'. --@ class_name (string) the name of the class --: (string) the category of the class; nil if unknown function p.get_class_category(class_name) local class_data = p.get_class_data(class_name) if class_data then for _, property in ipairs(class_data.Properties.string) do           if property._attr.name == "ClassCategory" then return property[1] end end end end

--% This function gets a class'. --@ class_name (string) the name of the class --: (string) the explorer order of the class, or nil if unknown function p.get_explorer_order(class_name) local class_data = p.get_class_data(class_name) if class_data then for _, property in ipairs(class_data.Properties.string) do           if property._attr.name == "ExplorerOrder" then return property[1] end end end end

--% This function gets a class'. --@ class_name (string) the name of the class --: (string) the explorer image index of the class, or nil if unknown function p.get_explorer_image_index(class_name) local class_data = p.get_class_data(class_name) if class_data then for _, property in ipairs(class_data.Properties.string) do           if property._attr.name == "ExplorerImageIndex" then return property[1] end end end end

--% This function gets a class'. --@ class_name (string) the name of the class --: (string) the preferred parent of the class, or nil if unknown function p.get_preferred_parent(class_name) local class_data = p.get_class_data(class_name) if class_data then for _, property in ipairs(class_data.Properties.string) do           if property._attr.name == "PreferredParent" then return property[1] end end end end

--% This function gets a class'. --% The summary can contain HTML markup that cannot be used in article text. --@ class_name (string) the name of the class --: (string) the summary of the class, or nil if unknown function p.get_class_summary(class_name) local class_data = p.get_class_data(class_name) if class_data then for _, property in ipairs(class_data.Properties.string) do           if property._attr.name == "summary" then return property[1] end end end end

--% This function gets an enum's summary. --% The summary can contain HTML markup that cannot be used in article text. --@ enum_name (string) the name of the enum --: (string) the summary of the enum, or nil if unknown function p.get_enum_summary(enum_name) local enum_data = p.get_enum_data(enum_name) if enum_data then for _, property in ipairs(enum_data.Properties.string) do           if property._attr.name == "summary" then return property[1] end end end end

--% This function gets the summaries of an enum's items. --% The summaries can contain HTML markup that cannot be used in article text. --@ enum_name (string) the name of the enum --: (table) a dictionary: keys are enum item names, values are summaries; nil if not found function p.get_enum_item_summaries(enum_name) local enum_data = p.get_enum_data(enum_name) if not enum_data then return end local item_summaries = {} if enum_data.Item then for _, item in pairs(enum_data.Item) do           local item_name local item_summary for _, item_property in pairs(item.Properties.string) do               if item_property._attr and item_property._attr.name then if item_property._attr.name == "Name" then item_name = item_property[1] elseif item_property._attr.name == "summary" then item_summary = item_property[1] end end end if item_name and item_summary then item_summaries[item_name] = item_summary end end end return item_summaries end

local function get_member_data(member_container_class, class_data, member_name) if not class_data.Item then return end for _, item in pairs(class_data.Item) do       if item._attr and item._attr.class and item._attr.class == member_container_class and item.Item then for _, member in pairs(item.Item) do               if member._attr and member._attr.class == "ReflectionMetadataMember" then -- There are a few places in the ReflectionMetadata file where member properties are not inside a Properties element. Since there are only 9 as of March 2019, we ignore them. -- The Humanoid class has multiple Properties elements, one for each property of the class, in a single ReflectionMetadataMember item. Since it is the only class doing this, we ignore it. if member.Properties and member.Properties.string then for _, member_property in pairs(member.Properties.string) do                           if member_property._attr.name == "Name" then if member_property[1] == member_name then return member else break end end end end end end end end end

--% This function returns the item for a property. --@ class_data (table) the class data, which can be obtained with --@ property_name (string) the name of the property --: (table) the item with information about the property, or nil if not found function p.get_property_data(class_data, property_name) return get_member_data("ReflectionMetadataProperties", class_data, property_name) end

--% This function returns the item for a member function. --@ class_data (table) the class data, which can be obtained with --@ function_name (string) the name of the member function --: (table) the item with information about the function, or nil if not found function p.get_function_data(class_data, function_name) local member_data = get_member_data("ReflectionMetadataFunctions", class_data, function_name) if member_data then return member_data else member_data = get_member_data("ReflectionMetadataYieldFunctions", class_data, function_name) if member_data then return member_data end end end

--% This function returns the item for an event. --@ class_data (table) the class data, which can be obtained with --@ event_name (string) the name of the event --: (table) the item with information about the event, or nil if not found function p.get_event_data(class_data, event_name) return get_member_data("ReflectionMetadataEvents", class_data, event_name) end

--% This function returns the item for a callback. --@ class_data (table) the class data, which can be obtained with --@ callback_name (string) the name of the callback --: (table) the item with information about the callback, or nil if not found function p.get_callback_data(class_data, callback_name) return get_member_data("ReflectionMetadataCallbacks", class_data, callback_name) end

--% This function gets a summary for a member. --% The summary can contain HTML markup that cannot be used in article text. --@ member_data (string) the member summary, or nil if not found function p.get_member_summary(member_data) for _, member_property in pairs(member_data.Properties.string) do       if member_property._attr.name == "summary" then return member_property[1] end end end

return p