Modul:Redirect hatnote: Unterschied zwischen den Versionen

increment iArg two at a time; better but still buggy
(still wrong, but slightly less wrong?)
(increment iArg two at a time; better but still buggy)
Zeile 13: Zeile 13:
function p.redirect(frame)
function p.redirect(frame)
-- Get the args table and work out the maximum arg key.
-- Get the args table and work out the maximum arg key.
--[[
local origArgs = frame:getParent().args
local origArgs = frame:getParent().args
local args = {}
local args = {}
Zeile 23: Zeile 25:
if v ~= '' then
if v ~= '' then
args[k] = v
args[k] = v
end
end
--]]
local args = require('Module:Arguments').getArgs(frame)
local maxArg = 0
for k, v in pairs(args) do
if type(k) == 'number' and k > maxArg then
maxArg = k
end
end
end
end
Zeile 38: Zeile 49:
-- Create the data table.
-- Create the data table.
local data = {}
local data = {}
local iArg = 1
local iArg = 0
local iData = 1
local iData = 1
while iArg < maxArg do
while iArg < maxArg do
iArg = iArg + 1
iArg = iArg + 2
local useTable = data[iData] or {}
local useTable = data[iData] or {}
local use, page, isLastUse
local use = args[iArg]
if iArg % 2 == 0 then
local page = args[iArg + 1]
use = args[iArg]
useTable[#useTable + 1] = page
if use ~= 'and' then
useTable.use = use
isLastUse = true
end
else
page = args[iArg]
useTable[#useTable + 1] = page
end
data[iData] = useTable
data[iData] = useTable
if isLastUse then
if use ~= 'and' then
useTable.use = use
iData = iData + 1
iData = iData + 1
end
end
mw.logObject(useTable)
end
end


Anonymer Benutzer