Module:Arraymap
Summary
Module similar in functionality to PageForms's arraymap.
==Simple==
{{#invoke:Arraymap |map
|vals=Álvar,Núñez ,, Cabeza,de Vaca,,|sep=,,
|varstr=xxx |map=(xxx) |outputsep=;\s
}}
Luafout op regel 25: bad argument #3 to 'gsub' (string/function/table expected)
Or, using unnamed, sequential approach:
{{#invoke:Arraymap |map |Álvar,Núñez ,, Cabeza, de Vaca,, |, |xxx |[xxx] |;\s}}
Luafout op regel 25: bad argument #3 to 'gsub' (string/function/table expected)
Special use cases
If sep needs to be a space, use %s?
Escaped syntax for curly braces and pipes
Escape {{... }} as %{%{ ... %}%}
Escape | as %
{{#invoke:Arraymap |map
|vals=Persoon/-1002367743,Persoon/400
|sep=,
|varstr=xxx
|map=%{%{#ask: [[xxx]] %mainlabel=- %?Has name= %}%}
|outputsep=;\s
|escaped=true
|fuzzy=false
}}
Luafout op regel 25: bad argument #3 to 'gsub' (string/function/table expected)--[[
{{#invoke:Arraymap
|vals=
|sep=
|varstr=
|map=
|outputsep=
]]--
local p = {}
p.map = function(frame)
local vals = frame.args.vals or mw.text.trim(frame.args[1]) or ""
local sep = frame.args.sep or mw.text.trim(frame.args[2]) or ","
--local valTable = {}
-- for val in string.gmatch( vals, sep ) do
-- table.insert( valTable, val)
-- end
local varstr = frame.args.varstr or mw.text.trim(frame.args[3]) or "@@@"
local map = frame.args.map or mw.text.trim(frame.args[4]) or ""
local outputsep = frame.args.outputsep or mw.text.trim(frame.args[5]) or ""
local valTable = {}
for val in string.gmatch( vals, sep ) do
local newVal = map.gsub( varstr, val )
-- replace varstr in map with val
table.insert( valTable, newVal)
end
local newVals = table.concat( valTable, outputsep )
return newVals
end
return p
