io.open() question

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
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

io.open() question

Post by Silver Ankh »

I have two directories: [LOVE2D directory] and [App directory]. When I start app from LOVE2D directory using love.exe "App directory", for every newImage, newSource, newFont etc. current directory is [App directory], only for io.open current directory is [LOVE2D directory]. Is this OK? Seems to be little bit inconsistent.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: io.open() question

Post by ivan »

The io. module doesn't work in Love2D as far as I know.
We use "love.filesystem" instead.
I don't think you should need access outside of the game folder.
For saving stuff, you are supposed to use the /%User/AppData/ folder.
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

Re: io.open() question

Post by Silver Ankh »

Is working for me. I used io.open and file:lines.
Now I found love.filesystem.lines :awesome:
I'll change this in my app for better consistency.
Thank you!
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: io.open() question

Post by zorg »

the io module does work, but it has a few shortcomings, mainly that it's OS-dependent how it works, and that you can't use that with löve's constructor functions (love.*.new*) since those use löve's own filesystem library. (Also, not specifically io-module related, but nowadays, OS-es think they have the right to dictate where programs can read/write, so that can also be a problem.)

Also, where the CWD or current working directory is is dependent on tons of things; even how a batch file is coded can mess with it:

Code: Select all

-- If your bat file is in the directory where love.exe is, then:
love "path/to/project/folder"
-- If it's in your project directory, where main.lua is, then:
"path/to/love.exe" .\
-- If it's anywhere else, then:
"path\to\love.exe" "path/to/project/folder"
All three of those might have the CWD at different locations, which is why you shouldn't rely on that.
You should use love.filesystem's directory querying functions instead.
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.
Silver Ankh
Prole
Posts: 11
Joined: Tue Dec 19, 2017 10:29 am

Re: io.open() question

Post by Silver Ankh »

@zorg
Thanks for the explanation!
Post Reply

Who is online

Users browsing this forum: baconhawka7x, slime and 47 guests