Daytoy a modulo ket mangited ti nalaka a panagproseso kadagiti argumento a maipasa manipud iti #invoke.
Inus-usar daytoy a modulo kadagiti mensahe ti sistema. Dagiti panagbaliw iti daytoy ket gapuanan dagiti dagus a panagbaliw iti interface ti agar-aramat iti Wiki Ilokano. Tapno maliklikan ti nakaro a pannakagulo, nasken nga umuna a masubokan dagiti ania man a panagbaliw kadagiti subpanid ti /pagipadasan wenno /pangsubok ti modulo, wenno iti bukodmo a pagipadasan. Mabalinton a mainayon dagiti nasubokan a panagbaliw iti maysa a panagurnos iti daytoy a modulo. Pangngaasi a pakitungtungan dagiti ania man a panagbaliw iti panid ti tungtungan sakbay nga isayangkat. |
Inus-usar daytoy a modulo kadagiti adu a panid, no baliwam adunto ti makadlaw. Pangngaasi nga umuna a subokan kadagiti subpanid ti /pagipadasan wenno /pangsubok, wenno iti bukodmo a subpanid, ken usigen a pagtungtungan dagiti binaliwan iti panid ti tungtungan sakbay nga isayangkat. |
Daytoy ket meta-modulo, a panggep nga us-usaren kadagiti sabali a modulo, ken nasken a saan a dagus a matawagan manipud iti #invoke. Dagiti langana ket mairaman ti:
...
.Ti umuna, nasken nga ikarga ti modulo. Daytoy ket aglaon ti maysa nga annong, a nanaganan ti getArgs
.
local getArgs = require('Modulo:Dagiti argumento').getArgs
Iti kalakaan a senario, mabalin nga usaren ti getArgs iti uneg ti annong. Ti karuay nga args
ket ti tabla nga aglaon kadagiti argumento manipud iti #invoke. (Kitaen pay dagiti adu a salaysay dita baba.)
local getArgs = require('Modulo:Dagiti argumento').getArgs local p = {} function p.main(frame) local args = getArgs(frame) -- Mapan ditoy ti nangruna a kodigo ti modulo. end return p
Nupay kasta, ti maisingasing a panagsanay ket ti panagusar ti annong para laeng ti panagproseso kadagiti argumento manipud iti #invoke. Ti kayatna a sawen daytoy ket no adda mangtawag manipud iti sabali a modulo ti Lua saanen a nasken ti adda iti magun-od a banag ti kuadro, a mangpasayaat daytoy ti panagpaandar.
local getArgs = require('Modulo:Dagiti argumento').getArgs local p = {} function p.main(frame) local args = getArgs(frame) return p._main(args) end function p._main(args) -- Mapan ditoy ti nangruna a kodigo ti modulo. end return p
No kayat nga agusar kadagiti adu nga annong ti panagusar kadagiti argumento, ken no kayat pay a maala manipud iti #invoke, mabalin ti agusar ti pangbalkot nga annnong.
local getArgs = require('Modulo:Dagiti argumento').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) -- Ti kodigo ti umuna nga annong ket mapan ditoy. end p.func2 = makeInvokeFunc('_func2') function p._func2(args) -- Ti kodigo ti maikadua nga annong ket mapan ditoy. end return p
Dagiti sumaganad a pagpilian ket mabalin a magun-od. Naipalawagda kadagiti paset dita baba.
local args = getArgs(frame, { trim = false, removeBlanks = false, valueFunc = function (key, value) -- Kodigo para iti panagproseso ti maysa nga argumento end, frameOnly = true, parentOnly = true, parentFirst = true, readOnly = true, noOverwrite = true })
Dagiti blanko nga argumento ket allilawenda dagiti agdadamo nga agkodkodigo iti panagbaliw kadagiti plantilia ti MediaWiki iti Lua. Iti eskritu ti plantilia, dagiti blanko a kuerdas ken dagiti kuerdas nga aglaon ti whitespace ket naikeddeng dagitoy a saan nga husto (false). Nupay kasta, iti Lua, dagiti blanko a kuerdas ken dagiti kuerdas nga aglaon ti whitespace ket naikeddengda nga agpaysao (true). Ti kayatna a sawen daytoy ket no dika mangikaskaso kadagiti kasta nga argumento no agsurat kadagiti modulo ti Lua, mabalin a matrato ti maysa a banag a kas agpayso dagiti nasken koma a matrato a kas saan a husto. Ti mangliklik daytoy, babaen ti kasisigud daytoy a modulo ket ikkatenna amin dagiti blanko nga argumento.
Iti maipada, ti whitespace ketmabalin a gapuanan kadagiti parikut no mangipanggep kadagiti pangipuesto nga argumento. Urayno ti whitespace ket makissayan para kadagiti nanaganan nga argumento nga agtaud manipud iti #invoke, daytoy ket mapreserba para kadagiti panangipuesto nga argumento. Kaaduan a saan a kinaynayat dagiti maipatinayon a whitespace, isu a daytoy a modulo ket kasisigud a kissayanna daytoy.
Nupay kasta, sagpaminsan met a kayat nga usaren dagiti blanko nga argumento a kas maikabilt, ken sagpaminsan met a kayat ti maipatinayon a whitespace. Daytoy ket nasken no pagbaliwen dagiti dadduma a plantilia iti kasisigud met laeng a pannakaisuratda. No kayat nga aramiden daytoy, iyasentar dagiti argumento ti trim
ken removeBlanks
iti false
.
local args = getArgs(frame, { trim = false, removeBlanks = false })
Sagpaminsan met a kayat nga ikkaten dagiti blanko nga argumento ngem ibati dagiti sabali, wenno kayat nga ikabil amin a panangipuesto nga argumento iti ababa a letra. Ti panagaramid kadagiti kastoy mabalin nga usaren ti pagpilian ti valueFunc
. Ti maikabil ti daytoy a pagpilian ket nasken nga annong a mangala kadagiti dua a parametro, key
ken value
, ken mangisubli ti agmaymaysa a pateg. Daytoy a pateg ti maalam no serrekan ti pagikabilan ti key
iti tabla ti args
.
Kas pagarigan 1: daytoy nga annong ket ipreserbana ti whitespace para iti umuna a pangipuesto nga argumento, ngem kissayanna amin dagiti sabali nga argumento ken ikkatenna amin dagiti sabali a blanko nga argumento.
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 })
Kas pagarigan 2: daytoy nga annong ket ikkatenna dagiti blanko nga argumento ken pagbaliwenna amin dagiti argumento iti ababa a letra, ngem sanna a kissayan ti whitespace manipud kadagiti pangipuesto a parametro.
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 })
Nota: dagiti annong dita ngato ket mapaay no maipasa ti maikabil a saana kita ti string
wenno nil
. Mabalin daytoy a kaso no usaren ti annong ti getArgs
iti nangruna nga annong ti modulo, ken dayta nga annong ket tawagan babaen ti sabali a modulo ti Lua. Iti daytoy a kaso, nasken a kitaen ti kita ti ikabil. Daytoy ket saan a parikut no agipasa ti annong a naipangruna para kadagiti argumento manipud iti #invoke (kasla no adda dagiti annong ti p.main
ken p._main
, wenno kapadana).
Kas pagarigan 1 ken 2 nga adda ti panagkita ti tipo |
---|
Kas pagarigan 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 }) Kas pagarigan 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 }) |
Pangngaasi pay a laglagipen a ti annong ti valueFunc
ket kankanayon a matawtawagan no ti maysa nga argumento ket kiniddaw manipud iti tabla ti args
, isu a no kaykayat ti nasayaat a panagpaandar siguraduen a saan nga agramid ti ania man a saan a nasayaat iti kodigo.
Dagiti argumento iti tabla ti args
ket mabalin nga agiddan a maipasa manipud iti agdama a kuadro wenno manipud iti nagannak a kuadro. Tapno maawatan ti kayatna a sawen daytoy, nasaysayaat ti mangited ti maysa a kas pagarigan. Kunaen tayo laengen nga adda ti maysa a modulo a tinawtawagan ti Modulo:KaspagariganArgs
. Daytoy a modulo ket imalditna dagiti dua nga umuna a pangipuesto nga argumento a maipasa.
Kodigo ti Modulo:KaspagariganArgs |
---|
local getArgs = require('Modulo:Dagiti argumento').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 |
Ti Modulo:KaspagariganArgs
ket matawaganton babaen ti Plantilia:KaspagariganArgs
, nga aglaon ti kodigo ti {{#invoke:KaspagariganArgs|main|firstInvokeArg}}
. Daytoy ket pataudenna ti resulta ti "firstInvokeArg".
No tawagentayo met ti Plantilia:KaspagariganArgs
, ti sumaganad ket isu ti mapasamak:
Kodigo | Resulta |
---|---|
{{KaspagariganArgs}} | firstInvokeArg |
{{KaspagariganArgs|firstTemplateArg}} | firstInvokeArg |
{{KaspagariganArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg secondTemplateArg |
Adda met dagiti tallo a pagpilian a maiyasentar tapno mabaliwan daytoy a panagkukua frameOnly
, ti parentOnly
ken parentFirst
. No iyasentar ti frameOnly
dagiti laeng argumento a maipasa manipud iti agdama a kuadro ti maawat; no iyasentar ti parentOnly
dagiti laeng argumento a maipasa manipud iti nagannak a kuadro ti maawat; ken no iyasentar ti parentFirst
maipasanto dagiti argumento manipud kadagiti agdama ken nagannak a kuadro, ngem ti nagannak a kuadro ket maiyunayunayto iti agdama a kuadro. Adda ditoy dagiti resulta kadagiti termino ti Plantilia:KaspagariganArgs
:
Kodigo | Resulta |
---|---|
{{KaspagariganArgs}} | firstInvokeArg |
{{KaspagariganArgs|firstTemplateArg}} | firstInvokeArg |
{{KaspagariganArgs|firstTemplateArg|secondTemplateArg}} | firstInvokeArg |
Kodigo | Resulta |
---|---|
{{KaspagariganArgs}} | |
{{KaspagariganArgs|firstTemplateArg}} | firstTemplateArg |
{{KaspagariganArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg |
Kodigo | Resulta |
---|---|
{{KaspagariganArgs}} | firstInvokeArg |
{{KaspagariganArgs|firstTemplateArg}} | firstTemplateArg |
{{KaspagariganArgs|firstTemplateArg|secondTemplateArg}} | firstTemplateArg secondTemplateArg |
Dagiti nota:
frameOnly
ken ti parentOnly
, ti modulo ket saanna nga laen dagiti ania man nga argumento manipud iti #invoke. Daytoy ti kayat a maaramid.parentFirst
ken frameOnly
ketawanto ti pagbanaganna.Ti pagpilian a wrappers ket inus-usar a manginagan ti limitado a bilang dagit iplantilia a kas dagiti plantilia a pangbalkot, isu dagitoy dagiti plantilia a ti panggepda laeng ket ti magawag ti modulo. No makaduktal ti modulo manipud iti plantilia a pangbalkot, kitaenna laeng dagiti argumento iti kuadro ti nagannak; no saan kitaenna laeng dagiti argumento iti kuadro a naipasa iti getArgs. Daytoy ket mangpalubos kadagiti modulo a matawagan babaen ti #invoke wenno babaen ti plantilia a pangbalkot nga awan ti pannakapukaw ti kasayaat ti panagpataray a mainaig ti panangkita kadagiti dua a kuadro ken ti kuadro ti nagannak para iti tunggal maysa a panagkita ti argumento.
Kas pagarigan, ti laeng linaon ti Plantilia:Igid a kahon (saan a mairaman dagiti etiketa ti
) ket {{#invoke:Side box|main}}
. Awan rebbengen ti panagkita kadagiti argumento a dagus a maipasa iti insasao iti #invoke para iti daytoy a plantilia, gapu ta awanton dagiti argumento a mainaganan idiay. Maliklikan ti panagkita kadagiti argumento a maipasa iti #invoke babaen ti panagusar ti pagpilian ti parentOnly , ngem no saan nga usaren daytoy ti #invoke ket saan to met a mabalin kadagiti sabali a panid. No kastoy dagiti kaso, ti |text=Some text
iti kodigo {{#invoke:Igid a kahon|main|text=Some text}}
ket kompletonto a saan a maikaskaso, urayno ania a panid ti nakausaranna. Babaen ti panagusar ti pagpilian ti wrappers
tapno mainaganan ti 'Plantilia:Igid a kahon' a kas pangbalkot, mabalin nga agbalin a maaramid ti {{#invoke:Igid a kahon|main|text=Some text}}
manipud iti kaaduan a pampanid, bayat a saanen a nasken nga agkita ti modulo kadagiti argumento iti panid ti Plantilia:Igid a kahon .
Dagiti pangbalkot ket mabalin a mainaganan a kas kuerdas, wenno rimpuook dagiti kuerdas.
local args = getArgs(frame, { wrappers = 'Plantilia:Pangbalkot a plantilia' })
local args = getArgs(frame, { wrappers = { 'Plantilia:Pangbalkot 1', 'Plantilia:Pangbalkot 2', -- Ti aniaman a bilang dagiti pangbalkot a plantilia ket mabalin a mainayon ditoy. } })
Dagiti nota:
getArgs
.Sagpaminsan a naserbi ti agsurat kadagitibaro a pateg iti tabla ti args. Daytoy ket posible iti kasisigud a pannakaiyasentar ti modulo. (Nupay kasta, laglagipen a nasaysayaat nga estilo ti panagkodigo ti agpartuat ti baro a tabla kadagiti baro a pateg ken kopiaen dagiti argumento manipud iti taba ti args no masapul.)
args.foo = 'dagiti pateg'
Mabalin a baliwan daytoy a panagkukua babaen ti pagpilian ti readOnly
and noOverwrite
. No maiyasentar ti readOnly
sannton a mabalin ti agsurat kadagiti ania man a pateg iti tabla ti args. No maiyasentar ti noOverwrite
, mabalinton ti agnayon kadagiti baro a pateg iti tabla, ngem saanen a mabalin ti agnayon ti pateg no suratanna manen dagiti ania man nga argumento a maipasa manipud iti #invoke.
Daytoy a modulo ket agus-usar kadagiti metatabla tapno agala kadagiti argumento manipud iti #invoke. Daytoy ket mangpalubos ti mangserrek kadagiti kuadro ti argumento ken dagiti argumento ti nagannak a kuadro a saan nga agusar ti annong ti pairs()
. Daytoy ket mabalin a makatulong no ti modulo ket maipasa a kas dagiti maikabil nga etiketa ti ...
.
Intono maserrekanen dagiti etiketa iti ...
manipud iti Lua, maproseso dagitoy babaen ti sopwer ti MediaWiki ken ti reperensia ket agparangto iti listaan ti reperensia. No mapan a mangikkat ti modulo kadagiti etiketa ti reperensia manipud iti maiparuar, ti addanto ket ti phantom a reperensia – ti reperensia nga agparang iti listaan ti reperensia, ngem awan ti biang a maisilpo ti daytoy. Daytoy ket parikut idin dagiti modulo nga agus-usar ti pairs()
tapno mangduktal no agusar kadagiti argumento manipud iti kudro wenno nagannak a kuadro, gapu ta dagita a modulo ket automatikoda a mangproseso ti amin a magun-od nga argumentoa.
Daytoy a modulo ket solbarenna daytoy a parikut babaen ti panagpalubos ti panagserrek kadagiti argumento ti kuadro ken nagannak a kuadro, bayat nga agal-ala pay laeng kadagitoy nga argumento no nasken. Nupay kasta, ti parikut ket rumsua pay laeng no usaren ti pairs(args)
kadagiti modulo,
Ti panagusar kadagiti metatabla ket adda met dagiti saan a nasayaat a pagbanaganna. Kaaduan kadagiti normal a ramramit ti tabla ti Lua ket saan a nasayaat nga agobra iti tabla ti args, a mairaman ti operator ti #
, ti anong ti next()
, ken dagiti annong ti biblioteka ti tabla. No ti panagusar kadagitoy ket nasken para iti modulo, nasken nga agusar ti bukod nga annong ti panagproseso ti argumento imbes nga usaren daytoy a modulo.
-- Daytoy a modulo ket mangited ti nalaka a panagproseso kadagiti argumento -- a maipasa iti Scribunto manipud ti #invoke. Daytoy ket saan a naikeddeng -- a mausar dagiti sabali a modulo ti Lua, ken nasken a saan a dagus a matawagan -- manipud ti #invoke. 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('/pagipadasan$', '') 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( "madi a pateg ti nainagan iti pagpilian ti 'valueFunc'" .. '(nakanamnama ti annong, ti naala ket ' .. 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( 'saan a makaisurat iti tekla ti tabla ti argumento "' .. tostring(key) .. '"; ti tabla ket mabasa laeng', 2 ) elseif options.noOverwrite and args[key] ~= nil then error( 'saan a makaisurat iti tekla ti tabla ti argumento "' .. tostring(key) .. '"; madi ti mangsurat manen kadagiti adda nga argumento', 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