Module:Array: Difference between revisions

Created Module:Array
 
ReisuDesign (talk | contribs)
Adds ability to have a second array within the array
 
Line 40: Line 40:
-- split string to array
-- split string to array
local array = lib.split(arrayString, separator, split_opt)
local array = lib.split(arrayString, separator, split_opt)
local array2 = args.array2 and lib.split(args.array2, args.arraysep2 or separator, split_opt) or nil
if array2 then
local product = {}
for _, item1 in ipairs(array) do
for _, item2 in ipairs(array2) do
table.insert(product, {item1, item2})
end
end
array = product
end


-- remove duplcates from array
-- remove duplcates from array
Line 54: Line 65:
for key, value in pairs(array) do
for key, value in pairs(array) do
local item = form
local item = form
local value2
if array2 then
value2 = value[2]
value = value[1]
end
item = item:gsub('{newline}', '\n')
item = item:gsub('{newline}', '\n')
item = item:gsub('{index}', key)
item = item:gsub('{index}', key)
Line 72: Line 90:
split(values, '2')
split(values, '2')
if value2 then item = item:gsub('{item2}', value2) end
item = item:gsub('{item}', value)
item = item:gsub('{item}', value)
item = item:gsub('{item([%d%.]*)}',
item = item:gsub('{item([%d%.]*)}',