Module:Range
Appearance
Unchecked
Documentation for this module may be created at Module:Range/doc
local x = {}
require("mw.language")
function x.main(frame)
local args = frame.args
local ret = {}
if table.getn(args) == 1 then
local start, stop, step = 0, args[1], 1
elseif table.getn(args) == 2 then
local start, stop, step = args[1], args[2], 1
elseif table.getn(args) == 3 then
local start, stop, step = args[1], args[2], args[3]
else
error("Blah!")
end
if (step > 0 and start >= step) or (step < 0 and start <= step) then
return "[]"
end
repeat
-- Because Lua has idiosyncratic list/array syntax that starts at 1 rather than 0...
ret[start + 1] = tostring(start)
start = start + 1
until start >= stop
ret = "[" .. table.concat(ret, ", ") .. "]"
return ret
end
return x