Reading files under Löve

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Reading files under Löve

Post 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)
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Reading files under Löve

Post 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.
User avatar
cag
Citizen
Posts: 65
Joined: Sun Jun 29, 2008 5:09 am

Re: Reading files under Löve

Post 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.
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Re: Reading files under Löve

Post 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.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Reading files under Löve

Post 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
MrPickle
Prole
Posts: 24
Joined: Thu Jul 10, 2008 11:43 pm
Location: United Kingdom, Lincolnshire

Re: Reading files under Löve

Post by MrPickle »

Ahh, cool.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests