Page 1 of 1

Reading files under Löve

Posted: Tue Sep 16, 2008 10:18 pm
by MrPickle
I'm struggling to read a file under löve?

I know love.filesystem.open( file ) but that returns a boolean? so how can that boolean be the file? I'm confused by that.

Could someone provide an example of how to open a file and read it line by line? (The tutorials could do with one on reading files if I do say so myself)

Re: Reading files under Löve

Posted: Tue Sep 16, 2008 10:45 pm
by Kuromeku
I believe it opens a buffer or some shit and the boolean is the success of it.

Once you have opened it you then need to manually read line by line or a given string length. Maybe you have come from an unprofessional shit thing like Garry's Mod where everything is handed to you on a plate with a knife, fork, and dessert. However, here you have almost direct access to the file system.

Re: Reading files under Löve

Posted: Wed Sep 17, 2008 2:01 am
by cag
Psst:
love.filesystem.newFile( filename, mode )

it's not *just* for making new files. you can create a buffer to open your file in with this as well!
that said, booleans are not files. however, booleans can tell you if something is successful or not. newFile returns a file, which can be opened.

Re: Reading files under Löve

Posted: Wed Sep 17, 2008 3:10 pm
by MrPickle
Kudomiku wrote:I believe it opens a buffer or some shit and the boolean is the success of it.

Once you have opened it you then need to manually read line by line or a given string length. Maybe you have come from an unprofessional shit thing like Garry's Mod where everything is handed to you on a plate with a knife, fork, and dessert. However, here you have almost direct access to the file system.
I haven't come from Garry's Mod, but I do play Garry's Mod and I've never coded for it, Löve is the only LUA experience I have.
If you really must know my background I started with TGE and I normally code with C++ & OpenGL but I had an idea and felt like making in with Löve.
cag wrote:Psst:
love.filesystem.newFile( filename, mode )

it's not *just* for making new files. you can create a buffer to open your file in with this as well!
that said, booleans are not files. however, booleans can tell you if something is successful or not. newFile returns a file, which can be opened.
I was reading the documentation and saw that, thought it would just be for creating files so I didn't have a look :P I'll take a gander at it.

Re: Reading files under Löve

Posted: Wed Sep 17, 2008 3:18 pm
by rude
Related info:
In the next version, you'll be able to use love.filesystem without having to manage file handles.

Code: Select all

-- Read file contents directly
contents = love.filesystem.read("filename.txt")

-- Iterate over the lines in a file:
for line in love.filesystem.lines("filename.txt") do
  ...
end

Re: Reading files under Löve

Posted: Wed Sep 17, 2008 6:56 pm
by MrPickle
Ahh, cool.