Module:ParameterCount/sandbox explained

-- This module produces a count of all the arguments passed to it.

local yesno = require('Module:Yesno')

-- Trim a stringlocal function trim(s) return s:match('^%s*(.-)%s*$')end

-- Test whether a string is blanklocal function isBlank(s) --mw.log("here?") --mw.log(s) --mw.log(s:find('%S')) --mw.log(not s:find('%S')) return not s:find('%S')end

-- Tests whether a string is a valid positional key, and if so, returns it. If-- the key is invalid, this returns nil.local function isPositionalKey(s) s = trim(s) if s:find('^[1-9][0-9]*$') then return tonumber(s) endend

-- Return the count of all arguments for which testFunc returns a truthy value.local function count(args, testFunc) local ret = 0 for key, val in pairs(args) do if testFunc(key, val) then --mw.log(key) --mw.log(val) ret = ret + 1 end end return retend

-- Check shared arguments and get the parent argument count.local function main(frame, testFunc) local blankifiedTestFunc local modified_count = 0 if yesno(frame.args.checkblanks) then -- Extend the test function to check for blanks as well. blankifiedTestFunc = function(key, val) if not isBlank(val) then return testFunc(key, val) end end modified_count = -1 else blankifiedTestFunc = testFunc end if frame.args.checkblanks then mw.log("here?") modified_count = modified_count - 1 end local module_count = count(frame.args, blankifiedTestFunc) local parent_count = count(frame:getParent.args, blankifiedTestFunc) return module_count + parent_count + modified_countend

return