Functions

sunting

The principal exports from this module are functions to generate characters that are, for one reason or another, awkward to specify directly in wiki markup. Because the characters are awkward to specify directly, it is convenient to provide a separate function for each supported character, rather than a single function that takes a character as a parameter. Each character-generation function generates a sequence of one or more characters; by default, 1 character, or optionally a parameter may specify a number of characters up to a bound specified in the module. The upper bound avoids gratuitous opportunities for mayhem.

Function bound returns the integer upper bound on sequence length for the character-generation functions.

The character-generation functions are as follows:

function character
leftBraces {
rightBraces }
leftSquareBrackets [
rightSquareBrackets ]
leftAngleBrackets <
rightAngleBrackets >
equalSigns =

local p = {}

function p.bound( )
	return 16
end

function p.leftBraces( frame )
	local x = frame.args[1]
	if (x == nil) then return "{" end
	x = tonumber( x )
	if (x == nil) then return "{" end
	if (x < 1) then return "" end
	return string.rep("{",math.min(math.floor(x),p.bound()))
end

function p.rightBraces( frame )
	local x = frame.args[1]
	if (x == nil) then return "}" end
	x = tonumber( x )
	if (x == nil) then return "}" end
	if (x < 1) then return "" end
	return string.rep("}",math.min(math.floor(x),p.bound()))
end

function p.leftSquareBrackets( frame )
	local x = frame.args[1]
	if (x == nil) then return "[" end
	x = tonumber( x )
	if (x == nil) then return "[" end
	if (x < 1) then return "" end
	return string.rep("[",math.min(math.floor(x),p.bound()))
end

function p.rightSquareBrackets( frame )
	local x = frame.args[1]
	if (x == nil) then return "]" end
	x = tonumber( x )
	if (x == nil) then return "]" end
	if (x < 1) then return "" end
	return string.rep("]",math.min(math.floor(x),p.bound()))
end

function p.leftAngleBrackets( frame )
	local x = frame.args[1]
	if (x == nil) then return "<" end
	x = tonumber( x )
	if (x == nil) then return "<" end
	if (x < 1) then return "" end
	return string.rep("<",math.min(math.floor(x),p.bound()))
end

function p.rightAngleBrackets( frame )
	local x = frame.args[1]
	if (x == nil) then return ">" end
	x = tonumber( x )
	if (x == nil) then return ">" end
	if (x < 1) then return "" end
	return string.rep(">",math.min(math.floor(x),p.bound()))
end

function p.equalSigns( frame )
	local x = frame.args[1]
	if (x == nil) then return "=" end
	x = tonumber( x )
	if (x == nil) then return "=" end
	if (x < 1) then return "" end
	return string.rep("=",math.min(math.floor(x),p.bound()))
end

return p