A question about writing and appending with love.filesystem

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
gristly
Prole
Posts: 2
Joined: Thu Feb 15, 2018 4:50 am

A question about writing and appending with love.filesystem

Post by gristly »

Hi, first time LOVE user here! I'm just getting into the API so forgive me if the answer here is obvious, but I googled around for a bit to no avail. On the LOVE wiki page for love.filesystem, it says:
Files that are opened for write or append will always be created in the save directory. The same goes for other operations that involve writing to the filesystem, like mkdir.
I'm curious to know if this means LOVE can, in all circumstances, only write to the save directory. Is it completely impossible to write to the source directory (the one containing main.lua)? If so, is there a way to ship a game such that things like config files (which will be modifiable ingame) are automatically placed in the user's save directory on install, or should I just store the initial values for these files in my source directory and then copy them into the save directory if they aren't found there?

Thanks!
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: A question about writing and appending with love.filesystem

Post by pgimeno »

Hello, welcome to the forums!

Once development finishes, the source directory is typically zipped and either renamed to .love or appended to the executable. Saving to that directory would mean to rezip what you save. Löve does not make this possible (it would take a disproportionately big amount of time and I/O to rezip the file, deleting the old version of it and adding the new one, and even more so if it's written dynamically, e.g. with seeks).

You can still use the pure Lua 'io' library instead of love.filesystem, if you want to write elsewhere.

But in the use case you're suggesting, if the config files need some kind of default or template, then yes, it would be best to copy it to your save dir and then modify that one.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: A question about writing and appending with love.filesystem

Post by raidho36 »

It's not like you would want users to be able to screw up the config file without being able to revert to defaults by deleting it, forcing complete re-install if anything goes wrong.
gristly
Prole
Posts: 2
Joined: Thu Feb 15, 2018 4:50 am

Re: A question about writing and appending with love.filesystem

Post by gristly »

Thanks both of you for your help! More than just an answer, I've gained an understanding :) Stoked to work with love!!
Post Reply

Who is online

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