모듈:연습장/Bluehill

위키백과, 우리 모두의 백과사전.
local p = {} --p stands for package

local inl = {} --inl stands for internal

function p.sum(frame)
	local last = tonumber(frame.args.last or frame.args[1] or nil)

	if last == nil then
		last = 100
		mw.log("Warning: last will be 100.")
	end

	local sum = 0

	for i = 1, last, 1 do
		sum = sum + i
	end

	return sum
end

function p.ninetynine()
	local x = ""
	local bs = ""

	for i = 99, 0, -1 do
		bs = inl.ninetynine_getbottle(i)
		x = x .. bs .. " of beer on the wall, " .. bs .. " of beer.\n"
		x = x .. (i == 0 and "Go to the store and buy some more, 99 bottles" or "Take one down and pass it around, " ..  inl.ninetynine_getbottle(i - 1)) .. " of beer on the wall.\n"
	end

	return x
end

function inl.ninetynine_getbottle(i)
	local r = ""

	if i == 0 then
		r = "No more bottles"
	elseif i == 1 then
		r = "1 bottle"
	else
		r = i .. " bottles"
	end

	return r
end

return p