Module:Iteminfo/idSets

local data = mw.loadData( 'Module:iteminfo/idSets/data' ) -- loading data

local trim = mw.text.trim -- cache local currentFrame local getArg = function(key) local value = currentFrame.args[key] if not value then return nil end value = trim(value) if value == '' then return nil else return value end end

local function get(setname, itemid) if not data[setname] then return nil end

if data[setname][itemid] == nil then return data[setname]['default'] else return data[setname][itemid] end end

return { -- returns all valid set sets, seperated by comma. -- also can be called by other module: require('Module:Iteminfo/idSets').getAllNames getAllNames = function local str for name,_ in pairs(data) do			if str then str = str .. ', ' .. name else str = name end end return str end,

-- returns the value for this item in that set. -- return value may be: --    ""(Empty string): setname is invaild. --    "nil": only for nullable sets. --    "true" / "false": for bool values. --    other number string: int or float values. value = function(frame) currentFrame = frame -- cache local setname = getArg(1) local itemid = tonumber(getArg(2)) or 0 return get(setname, itemid) end,

-- for module. getValue = function(setname, itemid) itemid = tonumber(itemid) or 0 return get(setname, itemid) end,

-- for template getSet = function(frame) currentFrame = frame -- cache local setname = getArg(1) if not data[setname] then return end local str for k,v in pairs(data[setname]) do			if k ~= "default" then if str then str = str .. ', ' .. k				else str = k				end end end return str end,

-- for module. getIdSet = function(setname) if not data[setname] then return nil end return data[setname] --readonly? end,

}