I was wondering how do I get a line into an array with lua in some sort of function
eg. FileToArray(“C:/file.txt”)?
I know I can use:
var = io.open(“file”)
Data = var:read()
But it only returns the 1st line, and no other lines.
Anyone know how to fix this or a different way? I’m new to lua and the file system stuff.
You can pass
"*a"to read function, it should read the whole file:And if you want to store each line in an array. Like Jane’s solution you can use
io:lines () – which returns iterator function (each call gives you a new line)