Module:Sandbox/Unready

From Northumberland Climbing
< Module:Sandbox
Revision as of 05:51, 31 July 2020 by Ianbirtwistle (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Scribunto Testing Area

Lua modules cannot exist as subpages in the User: namespace. Therefore, this sandbox is my experimental module.

Special:PrefixIndex/Module:Sandbox/Unready lists modules in this area.


local p = {}

--[[
Helper function that populates the argument list
There may be a mix of named and unnamed parameters

arg_list = names of expected parameters, whether named or unnamed
]]
local function getParameters( frame_args, arg_list )
	local new_args = {}
	local index = 1
	local value

	for i, arg in ipairs( arg_list ) do
		value = frame_args[arg]
		if value == nil then
			value = frame_args[index]
			index = index + 1
		end
		new_args[arg] = value
	end

	return new_args
end

function p.len( frame )
	local new_args = getParameters( frame.args, {'s'} )
	local s = new_args['s'] or ''

	return mw.ustring.len( s )
end

return p