Can love.filesystem.read skip custom linebreaks?

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.
User avatar
YounYokel
Prole
Posts: 39
Joined: Thu Oct 03, 2019 5:57 pm

Re: Can love.filesystem.read skip custom linebreaks?

Post by YounYokel »

pgimeno wrote: Fri Jan 31, 2020 9:11 pm Oh OK, so what you want is probably this:

Code: Select all

love.filesystem.read():gsub('\r?\n', ''):gsub('\\n', '\n')
Applied to your example:

Code: Select all

s = [[Hello World.

This is a test file which contains some text.\n

Thanks, bye!
]]
print((s:gsub('\r?\n', ''):gsub('\\n', '\n')))
--[[ prints:
Hello World.This is a test file which contains some text.
Thanks, bye!
--]]
Mind you, it doesn't work for any other escape.
Neat, it works like clockwork. Can you please share where I can learn these '\n', '\\n', '\r?', '%s', '%s$' like stuff?
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Can love.filesystem.read skip custom linebreaks?

Post by zorg »

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
pgimeno
Party member
Posts: 3549
Joined: Sun Oct 18, 2015 2:58 pm

Re: Can love.filesystem.read skip custom linebreaks?

Post by pgimeno »

I think the Lua manual is more relevant here, because there are some differences (most notably, that \123 takes decimal numbers instead of octal):

Patterns: see Lua manual 5.4.1 (these are only used with string.gsub, string.gmatch, string.match, string.find and the obsolete alias string.gfind)

Backslash escapes apply to every literal string, see Lua manual 2.1

(Note: The version of LuaJIT that comes with LÖVE has some Lua 5.2 extensions, including hexadecimal backslash escapes of the form \x2A, you can read about them here: LuaJIT extensions)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 87 guests