Module:Sandbox/Sameboat/m1

This is an old revision of this page, as edited by Sameboat (talk | contribs) at 16:08, 29 January 2015. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local getArgs = require('Module:Arguments').getArgs
 
local p = {}
 
local function makeInvokeFunction(funcName)
	-- makes a function that can be returned from #invoke, using
	-- [[Module:Arguments]].
	return function (frame)
		local args = getArgs(frame, {parentOnly = true})
		return p[funcName](args)
	end
end
 
p.row = makeInvokeFunction('_row')
function p._row(args)
	local somelist = args[1]
	local result
	result = ''
	local tmp = mw.text.split(somelist, '\n')
	for k, v in pairs(tmp) do
		if (k % 2 == 0) then
			result = result .. '|-\n!' .. k .. '\n|' .. v .. '\n'
		else
			result = result .. '|-\n!style="background:#f77"|' .. k .. '\n|' .. v .. '\n'
		end
	end
	result = '{|class="wikitable"\n' .. result .. '|}'
	return result
end
 
p.link = makeInvokeFunction('_link')
 
function p._link(args)
	local result
	result = 'Simple loop\n'
	for i = 10,100,10 do
		result = result .. ':' .. i .. '\n'
	end
	return result
end
 
return p