Sâta a-o contegnûo

Modulo:Arguments

Da Wikipedia

O mòdolo Arguments o l'é 'n mòdolo Lua pi-â gestión di argoménti pasæ da #invoke. O l'é 'n metamòdolo pensòu p'êse dêuviòu inte di âtri mòdoli e no gh'à da êse ciamòu con #invoke. E seu fonçioìn inclùddan:

  • Levâ i spàççi giànchi da-e estremitæ di argoménti e i argoménti vêui.
  • Pasâ i argoménti da-a cornîxe prezénte e da quélla moæ contenporaniaménte (védde chi aprêuvo pe ciù detàggi).
  • Pasâ i argoménti diretaménte da 'n âtro mòdolo Lua o da-a consòlle de debug.
  • Repigiâ i argoménti sôlo quànde sèrvan, p'evitâ di problêmi co-o tag <ref>…</ref>
  • Personalizâ vàrie caraterìstiche.

Ûzo de bâze

Prìmma de tùtto bezéugna caregâ o mòdolo. O contêgne a sôla fonçión ciamâ getArgs.

local getArgs = require('Modulo:Arguments').getArgs

Into câxo de bâze se peu dêuviâ getArgs diretaménte inta fonçión prinçipâ. A variàbile args a l'é 'na tabélla che, dòppo da ciamâ, a contegniâ i argoménti in arîvo da #invoke (véddi chi aprêuvo pe-i detàggi).

local getArgs = require('Modulo:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	-- Main module code goes here.
end

return p

A ògni mòddo, o mêgio scistêma o l'é quéllo de dêuviâ 'na fonçión dedicâ a procesâ i argoménti de #invoke de mòddo che se sto mòdolo chi o l'é ciamòu da un âtro mòdolo Lua, ciufîto che da 'n'instruçión #invoke, no gh'àgge da avéi 'na cornîxe a dispoxiçión, megiàndo coscì a performance.

local getArgs = require('Modulo:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	-- Main module code goes here.
end

return p

Se se veu che ciù fonçioìn dêuvian i mæximi argoménti, rendéndoli acescìbili da #invoke, se peu dêuviâ 'na fonçión de interfàccia.

local getArgs = require('Modulo:Arguments').getArgs

local function makeInvokeFunc(funcName)
	return function (frame)
		local args = getArgs(frame)
		return p[funcName](args)
	end
end

local p = {}

p.func1 = makeInvokeFunc('_func1')

function p._func1(args)
	-- Code for the first function goes here.
end

p.func2 = makeInvokeFunc('_func2')

function p._func2(args)
	-- Code for the second function goes here.
end

return p

Inpostaçioìn

L'é disponìbile de fonçioìn de ciù:

local args = getArgs(frame, {
	trim = false,
	removeBlanks = false,
	valueFunc = function (key, value)
		-- Code for processing one argument
	end,
	frameOnly = true,
	parentOnly = true,
	parentFirst = true,
	wrappers = {
		'Template:A wrapper template',
		'Template:Another wrapper template'
	},
	readOnly = true,
	noOverwrite = true
})

Levâ i spàççi giànchi

I argoménti vêui són de spésso 'n problêma pi-â conversción di template MediaWiki in Lua: inta scintàsci di template e strìnghe vêue e quélle formæ da spàççi són conscideræ fâse, pe cóntra in Lua són conscideræ vêe. P'evitâ sto problêma chi, o mòdolo o lêva in ötomàtico tùtti i argoménti vêui ò formæ sôlo da spàççi.

Quànde sèrvan i argoménti vêui ò i spàççi giànchi se peu impostâ e çèrnie trim e removeBlanks a false.

local args = getArgs(frame, {
	trim = false,
	removeBlanks = false
})

Formataçión personalizâ di argoménti

Se se veu levâ çèrti argoménti vêui, ma no di âtri, ò se veu che tùtti i argoménti poxiçiónali vêgnan minóscoli, se peu dêuviâ a çèrnia valueFunc. L'input de sta çèrnia o gh'à da êse 'na fonçión con doî paràmetri, key e value, e o restitoìsce 'n valô séncio, restitoîo quànde se acêde a-o cànpo key inta tabèlla args.

Prìmmo ezénpio: sta fonçión chi a consèrva i spàççi vêui pò-u prìmmo argoménto poxiçiónale, ma a o lêva da l'inprinçìpio e da-a fìn de tùtti i argoménti e quélli vêui.

local args = getArgs(frame, {
	valueFunc = function (key, value)
		if key == 1 then
			return value
		elseif value then
			value = mw.text.trim(value)
			if value ~= '' then
				return value
			end
		end
		return nil
	end
})

Segóndo ezénpio: sta fonçión chi a lêva i argoménti vêui e a convèrte quélli no vêui in minóscolo, ma a no lêva i spàççi da-i argoménti poxiçionâli.

local args = getArgs(frame, {
	valueFunc = function (key, value)
		if not value then
			return nil
		end
		value = mw.ustring.lower(value)
		if mw.ustring.find(value, '%S') then
			return value
		end
		return nil
	end
})

Nòtta: e fonçioìn chi de d'âto no fonçiónn-an se l'input o no l'é do tîpo string ò nil. Quésto o peu sucêde se l'é dêuviòu a fonçión getArgs inta fonçión prinçipâ do mòdolo e quélla fonçión a l'é reciamâ da 'n âtro modulo Lua. Pe evitâ sto problêma chi bezéugna dêuviâ 'na fonçión specìfica pe-i argoménti ciamâ da 'n #invoke (sàiva a dî co-ina fonçión p.main e 'na fonçión p._main).

Ezénpio 1
local args = getArgs(frame, {
	valueFunc = function (key, value)
		if key == 1 then
			return value
		elseif type(value) == 'string' then
			value = mw.text.trim(value)
			if value ~= '' then
				return value
			else
				return nil
			end
		else
			return value
		end
	end
})
Ezénpio 2
local args = getArgs(frame, {
	valueFunc = function (key, value)
		if type(value) == 'string' then
			value = mw.ustring.lower(value)
			if mw.ustring.find(value, '%S') then
				return value
			else
				return nil
			end
		else
			return value
		end
	end
})

Zaché a fonçión valueFunc a l'é ciamâ tòsto tùtte e vòtte che 'n argoménto o vêgne domandòu da-a tabélla args, bezéugna aseghiâse chò-u seu còdice o ségge eficénte.

Frame e frame poæ

I argoménti da tabélla args pêuan êse pasæ a-o mæximo moménto da-o frame prezénte (quéllo ciamòu con #invoke) ò da-o seu frame poæ (quéllo ch'o contêgne l'#invoke). Prezénpio, se gh'é 'n mòdolo ciamòu Module:ExampleArgs sto lì o stànpa i prìmmi doî argoménti poxiçiónali riçevûi.

Còdice de Modulo
ExampleArgs
local getArgs = require('Modulo:Arguments').getArgs
local p = {}

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local first = args[1] or ''
	local second = args[2] or ''
	return first .. ' ' .. second
end

return p


Module:ExampleArgs o l'é ciamòu da Template:ExampleArgs, ch'o contêgne o còdice {{#invoke:ExampleArgs|main|firstInvokeArg}}. Quésto o dà cómme rizultâto "firstInvokeArg".

I rizultâti poscìbili da ciamâ de Template:ExampleArgs són:

Còdice Rizultâto
{{ExampleArgs}} firstInvokeArg
{{ExampleArgs|firstTemplateArg}} firstInvokeArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstInvokeArg secondTemplateArg

Gh'é træ çèrnia da dêuviâ pe cangiâne o conportaménto: frameOnly, parentOnly e parentFirst. Se frameOnly o l'é true alôa l'é acetòu sôlo i argoménti pasæ da-o frame prezénte, se parentOnly o l'é true l'é acetòu sôlo i argoménti pasæ da-o frame ò template poæ e se parentFirst o l'é true l'é acetòu ségge i argoménti do frame prezénte che quélli do frame poæ, che gh'aviàn a prioritæ. Prezénpio, i rizultâti són:

frameOnly pe esclùdde i argoménti da-o template
Còdice Rizultâto
{{ExampleArgs}} firstInvokeArg
{{ExampleArgs|firstTemplateArg}} firstInvokeArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstInvokeArg
parentOnly pe avéi sôlo i argoménti da-o template
Còdice Rizultâto
{{ExampleArgs}}
{{ExampleArgs|firstTemplateArg}}î firstTemplateArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstTemplateArg secondTemplateArg
parentFirst pe avéi i argoménti da-o template che pìggian in scî argoménti da fonçión ch'a-i reciàmma
Còdice Rizultâto
{{ExampleArgs}} firstInvokeArg
{{ExampleArgs|firstTemplateArg}} firstTemplateArg
{{ExampleArgs|firstTemplateArg|secondTemplateArg}} firstTemplateArg secondTemplateArg

Nòtte

  1. Se tùtte dôe e çèrnie frameOnly e parentOnly són true, o mòdolo o no repìggia nisciùn argoménto da-a ciamâ de #invoke.
  2. Inte çèrte scitoaçioìn o frame poæ o poriéiva no êse disponìbile, prezénpio se a getArgs l'é pasòu o frame poæ ciufîto che quéllo prezénte. Inte sto câxo chi sôlo i argoménti do frame prezénte són dêuviæ, se parentOnly l'é vêo no l'é dêuviòu nisciùn argoménto e parentFirst e frameOnly no gh'à de efètti.

Wrappers

A çèrnia wrappers a l'é da dêuviâ pe specificâ 'n nùmero limitòu de "template de interfàccia", sàiva a dî di template che gh'àn l'ùnica fonçión de reciamâ 'n mòdolo Se o mòdolo o rilêva ch'o l'é stæto ciamòu da un di template da lìsta da çèrnia wrappers o contròlla sôlo che i argoménti do frame poæ, sedónca o contròlla sôlo che i argoménti into frame pasòu a getArgs. Quésto o permétte a-i mòdoli d'êse ciamæ da 'n #invoke ò da 'n template de interfàccia sénsa pèrdie inta performance asociâ a-o fæto de dovéi controlâ ségge o frame poæ che quéllo prezénte pe ògni intrâ a 'n argoménto.

Prezénpio o còdice do tempalte de en.wiki en:Template:Side box o l'é {{#invoke:Side box|main}} (levòu o contegnûo inte <noinclude>…</noinclude>). No gh'é de raxoìn pe controlâ i argoménti pasæ drîti a l'#invoke dæto che no gh'é de argoménti inta ciamâ into còdice do template. Se poriéiva evitâ de controlâli fàndo ûzo da çèrnia parentOnly, ma inte sto câxo chi l'#invoke o no fonçioniéiva se ciamâ da pàgine despægie da en:Template:Side box. Prezénpio se o mòdolo Side box o foîse reciamòu da 'n'âtra pàgina co-o còdice {{#invoke:Side box|main|text=Some text}} o valô do paràmetro text o saiéiva ignoròu. Dêuviàndo a çèrnia wrappers pe specificâ Template:Side box cómme "template de interfàccia", se peu fâ scîe che 'na ciamâ {{#invoke:Side box|main|text=Some text}} prezénte inte de âtre pàgine a fonçiónn-e ànche se o mòdolo o và avànti a evitâ de controlâ i argoménti se ciamòu da-o template Template:Side box.

E pàgine che contêgnan di template de interfàccia pêuan êse specificæ cómme strìnga ò cómme array de strìnghe.

I wrapper pêuan êse specificæ tànto cómme strìnga che cómme array de strìnghe.

local args = getArgs(frame, {
wrappers = 'Template:Wrapper template'
})


local args = getArgs(frame, {
wrappers = {
'Template:Wrapper 1',
'Template:Wrapper 2',
-- Any number of wrapper templates can be added here.
}
})

Nòtte:

  1. O mòdolo o riconósce in outomàtico se ciamòu da-a sotopàgina /sandbox de 'n template de interfàccia. Dónca no l'é necesâio specificâla.
  2. A çèrnia wrappers a càngio o default de çèrnie frameOnly, parentOnly e parentFirst. Prezénpio, se parentOnly o l'é mìsso in mòddo esplìcito a fâso, e ciamæ da-o template de interfàccia càregan tànto i argoménti do template prezénte che inte quéllo poæ, scibén che-e ciamæ pe mêzo de template diferénti da quélli specificæ cómme de interfàccia càrega sôlo i argoménti do frame prezénte.
  3. Se a decixón quànde a çèrnia "wrappers" a l'é indicâ a no l'é disponìbile, 'n frame poæ o mòdolo o dêuvia i argoménti do frame prezénte pasæ a getArgs.

Scrîve in sciâ tabélla args

De vòtte, poriéiva servî scrîve nêuvi valoî in sciâ tabélla args. Quésto l'é poscìbile dêuviàndo o valô de default de sto mòdolo chi. A ògni mòddoo, pò-u sòlito o l'é 'n mêgio stîle de codìfica che creê 'na tabélla nêuva dónde copiâ i argoménti necesâi da-a tabélla args e i nêuvi valoî.

args.foo = 'some value'

L'é poscìbile cangiâ sto conportaménto chi co-e çèrnie readOnly e noOverwrite. Se readOnly o l'é true alôa no l'é poscìbile scrîve di nêuvi valoî inta tabélla args. Se noOverwrite o l'é true, l'é poscìbile azónze di nêuvi valoî ma no se peu cangiâ 'n valô pasòu da l'#invoke.

Tag Ref

Sto mòdolo chi o l'adêuvia metatable pe repigiâ i argoménti da #invoke sénsa dêuviâ a fonçión pairs() pe intrâ a-o frame prezénte e a-o frame poæ. Quésto o peu êse d'agiùtto se i argoménti pasæ a-o mòdolo pêuan contegnî tag <ref>…</ref>.

Quànde 'n mòdolo Lua o l'acêde a 'n argoménto ch'o contêgne 'n tag <ref>…</ref>, sto chi o l'é sùbito procesòu da-o software Mediawiki e o seu contegnûo o l'é azónto inta lìsta de nòtte a-o fóndo da pàgina. Se pe quàrche motîvo o mòdolo o levàsse da-o rizultâto ch'o restitoìsce l'argoménto ch'o contêgne o tag ref sto chi o crêa 'na nòtta fantaxîma — 'na nòtta ch'a l'apâre inta lìsta de nòtte, ma sénsa de nùmeri dónde conligâse. Sto chi o l'é stæto 'n problêma co-i mòdoli ch'adêuvian a fonçión pairs() pe rilevâ l'ûzo di argoménti da-o frame prezénte ò da-o frame poæ, dæto che quésti procèssan in outomàtico tùtti i argoménti a dispoxiçión.

Sto mòdolo chi o risólve o problêma permeténdo l'intrâ tànto a-i argoménti do frame prezénte che a quélli do frame poæ, repigiàndone bén i argoménti sôlo quand'o l'é necesâio. A ògni mòddo, o problêma o se prezénte tórna se l'é dêuviòu a fonçión pairs(args) inte quàrche pónto do mòdolo.

Lìmiti conosciûi

Dêuviâ e metatable o gh'à di svantàggi. A ciù pàrte de fonçioìn Lua pe-e tabélle a no fonçiónn-a bén in sciâ tabélla args, inclûzo l'òperatô #, a fonçión next() e-e fonçioìn da libràia table. Se l'é inportànte pò-u mòdolo l'ûzo de ste fonçioìn chi, bezéugna procesâ i argoménto co-ina pròpia fonçión in càngio de dêuviâ sto mòdolo chi.


-- This module provides easy processing of arguments passed to Scribunto from
-- #invoke. It is intended for use by other Lua modules, and should not be
-- called from #invoke directly.

local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType

local arguments = {}

-- Generate four different tidyVal functions, so that we don't have to check the
-- options every time we call it.

local function tidyValDefault(key, val)
	if type(val) == 'string' then
		val = val:match('^%s*(.-)%s*$')
		if val == '' then
			return nil
		else
			return val
		end
	else
		return val
	end
end

local function tidyValTrimOnly(key, val)
	if type(val) == 'string' then
		return val:match('^%s*(.-)%s*$')
	else
		return val
	end
end

local function tidyValRemoveBlanksOnly(key, val)
	if type(val) == 'string' then
		if val:find('%S') then
			return val
		else
			return nil
		end
	else
		return val
	end
end

local function tidyValNoChange(key, val)
	return val
end

local function matchesTitle(given, title)
	local tp = type( given )
	return (tp == 'string' or tp == 'number') and mw.title.new( given ).prefixedText == title
end

local translate_mt = { __index = function(t, k) return k end }

function arguments.getArgs(frame, options)
	checkType('getArgs', 1, frame, 'table', true)
	checkType('getArgs', 2, options, 'table', true)
	frame = frame or {}
	options = options or {}

	--[[
	-- Set up argument translation.
	--]]
	options.translate = options.translate or {}
	if getmetatable(options.translate) == nil then
		setmetatable(options.translate, translate_mt)
	end
	if options.backtranslate == nil then
		options.backtranslate = {}
		for k,v in pairs(options.translate) do
			options.backtranslate[v] = k
		end
	end
	if options.backtranslate and getmetatable(options.backtranslate) == nil then
		setmetatable(options.backtranslate, {
			__index = function(t, k)
				if options.translate[k] ~= k then
					return nil
				else
					return k
				end
			end
		})
	end

	--[[
	-- Get the argument tables. If we were passed a valid frame object, get the
	-- frame arguments (fargs) and the parent frame arguments (pargs), depending
	-- on the options set and on the parent frame's availability. If we weren't
	-- passed a valid frame object, we are being called from another Lua module
	-- or from the debug console, so assume that we were passed a table of args
	-- directly, and assign it to a new variable (luaArgs).
	--]]
	local fargs, pargs, luaArgs
	if type(frame.args) == 'table' and type(frame.getParent) == 'function' then
		if options.wrappers then
			--[[
			-- The wrappers option makes Module:Arguments look up arguments in
			-- either the frame argument table or the parent argument table, but
			-- not both. This means that users can use either the #invoke syntax
			-- or a wrapper template without the loss of performance associated
			-- with looking arguments up in both the frame and the parent frame.
			-- Module:Arguments will look up arguments in the parent frame
			-- if it finds the parent frame's title in options.wrapper;
			-- otherwise it will look up arguments in the frame object passed
			-- to getArgs.
			--]]
			local parent = frame:getParent()
			if not parent then
				fargs = frame.args
			else
				local title = parent:getTitle():gsub('/sandbox$', '')
				local found = false
				if matchesTitle(options.wrappers, title) then
					found = true
				elseif type(options.wrappers) == 'table' then
					for _,v in pairs(options.wrappers) do
						if matchesTitle(v, title) then
							found = true
							break
						end
					end
				end

				-- We test for false specifically here so that nil (the default) acts like true.
				if found or options.frameOnly == false then
					pargs = parent.args
				end
				if not found or options.parentOnly == false then
					fargs = frame.args
				end
			end
		else
			-- options.wrapper isn't set, so check the other options.
			if not options.parentOnly then
				fargs = frame.args
			end
			if not options.frameOnly then
				local parent = frame:getParent()
				pargs = parent and parent.args or nil
			end
		end
		if options.parentFirst then
			fargs, pargs = pargs, fargs
		end
	else
		luaArgs = frame
	end

	-- Set the order of precedence of the argument tables. If the variables are
	-- nil, nothing will be added to the table, which is how we avoid clashes
	-- between the frame/parent args and the Lua args.
	local argTables = {fargs}
	argTables[#argTables + 1] = pargs
	argTables[#argTables + 1] = luaArgs

	--[[
	-- Generate the tidyVal function. If it has been specified by the user, we
	-- use that; if not, we choose one of four functions depending on the
	-- options chosen. This is so that we don't have to call the options table
	-- every time the function is called.
	--]]
	local tidyVal = options.valueFunc
	if tidyVal then
		if type(tidyVal) ~= 'function' then
			error(
				"bad value assigned to option 'valueFunc'"
					.. '(function expected, got '
					.. type(tidyVal)
					.. ')',
				2
			)
		end
	elseif options.trim ~= false then
		if options.removeBlanks ~= false then
			tidyVal = tidyValDefault
		else
			tidyVal = tidyValTrimOnly
		end
	else
		if options.removeBlanks ~= false then
			tidyVal = tidyValRemoveBlanksOnly
		else
			tidyVal = tidyValNoChange
		end
	end

	--[[
	-- Set up the args, metaArgs and nilArgs tables. args will be the one
	-- accessed from functions, and metaArgs will hold the actual arguments. Nil
	-- arguments are memoized in nilArgs, and the metatable connects all of them
	-- together.
	--]]
	local args, metaArgs, nilArgs, metatable = {}, {}, {}, {}
	setmetatable(args, metatable)

	local function mergeArgs(tables)
		--[[
		-- Accepts multiple tables as input and merges their keys and values
		-- into one table. If a value is already present it is not overwritten;
		-- tables listed earlier have precedence. We are also memoizing nil
		-- values, which can be overwritten if they are 's' (soft).
		--]]
		for _, t in ipairs(tables) do
			for key, val in pairs(t) do
				if metaArgs[key] == nil and nilArgs[key] ~= 'h' then
					local tidiedVal = tidyVal(key, val)
					if tidiedVal == nil then
						nilArgs[key] = 's'
					else
						metaArgs[key] = tidiedVal
					end
				end
			end
		end
	end

	--[[
	-- Define metatable behaviour. Arguments are memoized in the metaArgs table,
	-- and are only fetched from the argument tables once. Fetching arguments
	-- from the argument tables is the most resource-intensive step in this
	-- module, so we try and avoid it where possible. For this reason, nil
	-- arguments are also memoized, in the nilArgs table. Also, we keep a record
	-- in the metatable of when pairs and ipairs have been called, so we do not
	-- run pairs and ipairs on the argument tables more than once. We also do
	-- not run ipairs on fargs and pargs if pairs has already been run, as all
	-- the arguments will already have been copied over.
	--]]

	metatable.__index = function (t, key)
		--[[
		-- Fetches an argument when the args table is indexed. First we check
		-- to see if the value is memoized, and if not we try and fetch it from
		-- the argument tables. When we check memoization, we need to check
		-- metaArgs before nilArgs, as both can be non-nil at the same time.
		-- If the argument is not present in metaArgs, we also check whether
		-- pairs has been run yet. If pairs has already been run, we return nil.
		-- This is because all the arguments will have already been copied into
		-- metaArgs by the mergeArgs function, meaning that any other arguments
		-- must be nil.
		--]]
		if type(key) == 'string' then
			key = options.translate[key]
		end
		local val = metaArgs[key]
		if val ~= nil then
			return val
		elseif metatable.donePairs or nilArgs[key] then
			return nil
		end
		for _, argTable in ipairs(argTables) do
			local argTableVal = tidyVal(key, argTable[key])
			if argTableVal ~= nil then
				metaArgs[key] = argTableVal
				return argTableVal
			end
		end
		nilArgs[key] = 'h'
		return nil
	end

	metatable.__newindex = function (t, key, val)
		-- This function is called when a module tries to add a new value to the
		-- args table, or tries to change an existing value.
		if type(key) == 'string' then
			key = options.translate[key]
		end
		if options.readOnly then
			error(
				'could not write to argument table key "'
					.. tostring(key)
					.. '"; the table is read-only',
				2
			)
		elseif options.noOverwrite and args[key] ~= nil then
			error(
				'could not write to argument table key "'
					.. tostring(key)
					.. '"; overwriting existing arguments is not permitted',
				2
			)
		elseif val == nil then
			--[[
			-- If the argument is to be overwritten with nil, we need to erase
			-- the value in metaArgs, so that __index, __pairs and __ipairs do
			-- not use a previous existing value, if present; and we also need
			-- to memoize the nil in nilArgs, so that the value isn't looked
			-- up in the argument tables if it is accessed again.
			--]]
			metaArgs[key] = nil
			nilArgs[key] = 'h'
		else
			metaArgs[key] = val
		end
	end

	local function translatenext(invariant)
		local k, v = next(invariant.t, invariant.k)
		invariant.k = k
		if k == nil then
			return nil
		elseif type(k) ~= 'string' or not options.backtranslate then
			return k, v
		else
			local backtranslate = options.backtranslate[k]
			if backtranslate == nil then
				-- Skip this one. This is a tail call, so this won't cause stack overflow
				return translatenext(invariant)
			else
				return backtranslate, v
			end
		end
	end

	metatable.__pairs = function ()
		-- Called when pairs is run on the args table.
		if not metatable.donePairs then
			mergeArgs(argTables)
			metatable.donePairs = true
		end
		return translatenext, { t = metaArgs }
	end

	local function inext(t, i)
		-- This uses our __index metamethod
		local v = t[i + 1]
		if v ~= nil then
			return i + 1, v
		end
	end

	metatable.__ipairs = function (t)
		-- Called when ipairs is run on the args table.
		return inext, t, 0
	end

	return args
end

return arguments