File I/O with bytes

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
User avatar
FroggestSpirit
Prole
Posts: 11
Joined: Tue Jan 26, 2016 7:13 pm

File I/O with bytes

Post by FroggestSpirit »

I'm a little stuck with having code create, or load an existing file, and write to it.

Code: Select all

function love.load(arg)
	love.filesystem.setIdentity("fileTest")
	str = string.char(72,101,108,108,111,10) -- "Hello\n"
	love.filesystem.write("test.bin",str)
	love.window.close()
end
That's my code right now, but it does nothing to test.bin which already exists
This isn't easy to say, but…
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: File I/O with bytes

Post by zorg »

Hi!
Could you try this instead, and report back on the results?:

Code: Select all

function love.load(arg)
   love.filesystem.setIdentity("fileTest")
   str = string.char(72,101,108,108,111,10) -- "Hello\n"
   local result = love.filesystem.write("test.bin",str)
   print(result)
   love.window.close()
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
FroggestSpirit
Prole
Posts: 11
Joined: Tue Jan 26, 2016 7:13 pm

Re: File I/O with bytes

Post by FroggestSpirit »

@zorg it ended up not doing anything. I moved the print command to a love.draw function, and remove the window closing, but it still came up with nothing displayed
This isn't easy to say, but…
Xugro
Party member
Posts: 114
Joined: Wed Sep 29, 2010 8:14 pm

Re: File I/O with bytes

Post by Xugro »

Your Code works on my machine. Have you looked in the right place (see: https://love2d.org/wiki/love.filesystem)? The file test.bin is not saved where the .love file is. You have to look in the save directory of love.
User avatar
FroggestSpirit
Prole
Posts: 11
Joined: Tue Jan 26, 2016 7:13 pm

Re: File I/O with bytes

Post by FroggestSpirit »

Xugro wrote:Your Code works on my machine. Have you looked in the right place (see: https://love2d.org/wiki/love.filesystem)? The file test.bin is not saved where the .love file is. You have to look in the save directory of love.
Thank you, I found it in the path specified. Is there a way I can change it to use the path of the source or .love file?
This isn't easy to say, but…
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: File I/O with bytes

Post by zorg »

Through the FFI, you can do that, but it has some issues, mainly that you can't guarantee the OS gives your program the rights to actually edit/modify files in that folder, or that the folder you want to be writable won't be the one the below code sets, and that if you have files opened elsewhere, changing the writable directory will fail.
With that said, something like this might work.
I'd only ever use this for some personal projects of mine, where i know what the damage this might be able to cause :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
FroggestSpirit
Prole
Posts: 11
Joined: Tue Jan 26, 2016 7:13 pm

Re: File I/O with bytes

Post by FroggestSpirit »

Thank you for the replies! If I end up doing a music editing program, I'll probably use it as a fused-exe, because from what I understand, you can have it read/write files in the same directory
This isn't easy to say, but…
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 4 guests