Module:AttributeData: Difference between revisions
Jump to navigation
Jump to search
initial, get_attr_category |
m get_attr_category for restructured attribute data |
||
Line 11: | Line 11: | ||
return nil | return nil | ||
end | end | ||
function isElementInArray(array, element) | |||
for _, value in ipairs(array) do | |||
if value == element then | |||
return true | |||
end | |||
end | |||
return false | |||
end | |||
--{{#invoke:AttributeData|get_attr_category|ATTR_NAME}}-- | --{{#invoke:AttributeData|get_attr_category|ATTR_NAME}}-- | ||
Line 16: | Line 26: | ||
local attr_name = frame.args[1] | local attr_name = frame.args[1] | ||
for category, attributes in pairs(data) do | |||
if isElementInArray(attributes, attr_name) then | |||
return category | |||
return | end | ||
end | |||
return nil | |||
end | end | ||
return p | return p |
Revision as of 22:05, 13 September 2024
Documentation for this module may be created at Module:AttributeData/doc
local p = {};
local data = mw.loadJsonData("Data:AttributeData.json")
-- returns the table of a specific item
function get_json_item(name)
for i,v in pairs(data) do
if (i == name) then
return v
end
end
return nil
end
function isElementInArray(array, element)
for _, value in ipairs(array) do
if value == element then
return true
end
end
return false
end
--{{#invoke:AttributeData|get_attr_category|ATTR_NAME}}--
p.get_attr_category = function(frame)
local attr_name = frame.args[1]
for category, attributes in pairs(data) do
if isElementInArray(attributes, attr_name) then
return category
end
end
return nil
end
return p