Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 02:31, 21 December 2024 by PenguinEncounter (talk | contribs) ('first')

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

local exports = {}

local ordinals = {
	[1] = "first",
	[2] = "second",
	[3] = "third",
	[4] = "fourth"
}

local function trim(str)
	return str:gsub("^%s*", ""):gsub("%s*$", "")
end

local col_template = trim [=[
=== <code>c$n</code> <span id="field_c$n"></span> ===
{{aliases|$n}}

The $ord column as a {{type|Vector$T}}. Equivalent to calling [[#getColumn|<code>getColumn($n)</code>]].
]=]
local row_template = trim [=[
=== <code>r$n</code> <span id="field_r$n"></span> ===

The $ord row as a {{type|Vector$T}}. Equivalent to calling [[#getRow|<code>getRow($n)</code>]].
]=]
local item_template = trim [=[
=== <code>v$y$x</code> <span id="field_v$y$x"></span> ===

The value in row $y and column $x.
]=]

function exports.run(frame)
	local input_args = frame.args
	local object_size = input_args.size or error "No size provided (size=)"
	object_size = tonumber(object_size) or error "Size provided was not a number"
	
	local col_t2 = col_template:gsub("$T", tostring(object_size))
	local row_t2 = row_template:gsub("$T", tostring(object_size))
	
	local parts = {}
	for i = 1, object_size do
		parts[#parts + 1] = col_t2:gsub("$n", tostring(i)):gsub("$ord", ordinals[i])
	end
	for i = 1, object_size do
		parts[#parts + 1] = row_t2:gsub("$n", tostring(i)):gsub("$ord", ordinals[i])
	end
	for x = 1, object_size do
		for y = 1, object_size do
			parts[#parts + 1] = item_template:gsub("$y", tostring(y)):gsub("$x", tostring(x))
		end
	end
	
	local packaged = table.concat(parts, "\n\n")
	return frame:preprocess(packaged)
end

return exports