From WikiChip
Difference between revisions of "Module:comp"

Line 5: Line 5:
 
         local t={} ; i=1
 
         local t={} ; i=1
 
         for str in string.gmatch(str, "([^"..sep.."]+)") do
 
         for str in string.gmatch(str, "([^"..sep.."]+)") do
                 t[i] = str
+
                 t[i] = str:match "^%s*(.-)%s*$"
 
                 i = i + 1
 
                 i = i + 1
 
         end
 
         end

Revision as of 21:41, 17 May 2017

Documentation for this module may be created at Module:comp/doc

function split(str, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={} ; i=1
        for str in string.gmatch(str, "([^"..sep.."]+)") do
                t[i] = str:match "^%s*(.-)%s*$"
                i = i + 1
        end
        return t
end


local m = {}

function m.mpu_comp(frame)
  local wikichip = require("Module:wikichip")
	
  if not frame.args.list then
    return 'Error: Missing chip list to compare!'
  end
	
  local list = split(frame.args.list, ',')
  local s = ''
  
  for key, chip_name in pairs(list) do
    local chip = wikichip:new(chip_name)
    if not chip.is_valid() then
    	return '<strong>"' .. chip_name .. '"</strong> cannot be found.';
	end
  end
  
  return s
  
end

return m