RosettaCodeData/Task/Read-a-specific-line-from-a-file/Lua/read-a-specific-line-from-a-file.lua

11 lines
265 B
Lua
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
function fileLine (lineNum, fileName)
local count = 0
for line in io.lines(fileName) do
count = count + 1
if count == lineNum then return line end
end
error(fileName .. " has fewer than " .. lineNum .. " lines.")
2015-02-20 00:35:01 -05:00
end
2020-02-17 23:21:07 -08:00
print(fileLine(7, "test.txt"))