Page 1 of 2

Can't start new lines with love.filesystem?

Posted: Fri Mar 18, 2011 9:54 pm
by FishofMuu
Okay, this has been really bugging me for like an hour now.

Code: Select all

file = love.filesystem.newFile("test.txt")
file:open('a')
stringy = ""
stringy = stringy.."one\n"
stringy = stringy.."\ntwo"
stringy = stringy.."three"
stringy = stringy.."\n"
stringy = stringy.."four"
file:write(stringy)
print(stringy)
This will get me a file with "onetwothreefour" all on one line. The console will get it separated into different lines.

If I do:

Code: Select all

file = love.filesystem.newFile("test.txt")
file:open('a')
file:write("one\n")
file:write("\ntwo")
file:write("three")
file:write("\n")
file:write("four")
I again get "onetwothreefour". Obviously, love.filesystem ignores \n. So... I guess the question is how do I start a new line in a file?

Re: Can't start new lines with love.filesystem?

Posted: Fri Mar 18, 2011 9:57 pm
by slime
Have you tried \r or \r\n? (wild guess)

Re: Can't start new lines with love.filesystem?

Posted: Fri Mar 18, 2011 10:01 pm
by FishofMuu
Okay, I KNEW it was something stupidly easy like that. I'm totally new to LUA this week, so I've never even seen \r before. Thank you.

Re: Can't start new lines with love.filesystem?

Posted: Fri Mar 18, 2011 10:09 pm
by nevon
FishofMuu wrote:Okay, I KNEW it was something stupidly easy like that. I'm totally new to LUA this week, so I've never even seen \r before. Thank you.
That's actually a Windows idiosyncrasy, IIRC. In OS X or any *NIX system, \n will do exactly what you expect it to. It's only in Windows that you have to do \r\n.

Re: Can't start new lines with love.filesystem?

Posted: Fri Mar 18, 2011 10:57 pm
by Robin
Would it be a good idea to let Files do automatic new-line conversion on Windows?

Re: Can't start new lines with love.filesystem?

Posted: Sat Mar 19, 2011 9:52 am
by BlackBulletIV
Wow, this is a pretty bad cross-platform issue. Has an issue been created for this?

Re: Can't start new lines with love.filesystem?

Posted: Sat Mar 19, 2011 4:54 pm
by tentus
The following code works just fine on my windows XP and windows 7 machines, newlines behave exactly how the *nix user in me expects. (Pruned somewhat for readability.)

Code: Select all

function saveOptions()
	local set = ""
	set = set .. "-- Save File\n"
	set = set .. "-- Created on " .. os.date("%c") .. "\n\n"
	local file = love.filesystem.newFile("settings.lua")
	file:open('w')
	file:write(set)
	file:close()
end

Re: Can't start new lines with love.filesystem?

Posted: Sat Mar 19, 2011 5:17 pm
by bartbes
You're both wrong and right. It depends on the editor you open it in. Notepad needs \r\n, but wordpad for example works with just \n as well.

Re: Can't start new lines with love.filesystem?

Posted: Sat Mar 19, 2011 8:26 pm
by BlackBulletIV
bartbes wrote:You're both wrong and right. It depends on the editor you open it in. Notepad needs \r\n, but wordpad for example works with just \n as well.
Oh, I thought he was printing it to the console to test, not viewing in Notepad...

Re: Can't start new lines with love.filesystem?

Posted: Sun Mar 20, 2011 7:21 am
by FishofMuu
bartbes wrote:You're both wrong and right. It depends on the editor you open it in. Notepad needs \r\n, but wordpad for example works with just \n as well.
Ooooooh, alright. That makes a bit more sense now. Was pulling my hair out over something so simple. I code in Notepad++, but I open random txt files in notepad.