about summary refs log tree commit diff stats
path: root/source_file.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-08-30 19:04:06 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-08-30 19:04:06 -0700
commitf82c0de5020437bf45afa8d4e441437801466af6 (patch)
tree2aa807519b085bb82dc48269ed683636a5f2b45c /source_file.lua
parent7e97a2a1e7564c410236c012d7a6c4b0f141484d (diff)
downloadlines.love-f82c0de5020437bf45afa8d4e441437801466af6.tar.gz
cleaner API for file-system access
Thanks to physfs and nativefs.lua

nativefs still introduces some inconsistencies with love.filesystem with
relative paths:

  * love.fs.read: reads from save dir if it exists, falls back to source dir if not
  * nativefs.read: reads from save dir if it exists, falls back to source dir if not ✓

  * love.fs.write: always writes to save dir
  * nativefs.write: always writes to source dir (since no restrictions)

  * love.fs.newFile followed by file:open('r'): reads from save dir if it exists, source dir if not
  * nativefs.newFile followed by file:open('r'): always reads from working dir

  * love.fs.newFile followed by file:open('w'): always writes to save dir
  * nativefs.newFile followed by file:open('w'): always writes to working dir

So avoid using relative paths with App primitives.
Diffstat (limited to 'source_file.lua')
-rw-r--r--source_file.lua5
1 files changed, 3 insertions, 2 deletions
diff --git a/source_file.lua b/source_file.lua
index 3eaf6c3..d285e0d 100644
--- a/source_file.lua
+++ b/source_file.lua
@@ -10,8 +10,9 @@ function file_exists(filename)
   end
 end
 
+-- the source editor supports only files in the save dir, not even subdirectories
 function load_from_disk(State)
-  local infile = App.open_for_reading(State.filename)
+  local infile = App.open_for_reading(App.save_dir..State.filename)
   State.lines = load_from_file(infile)
   if infile then infile:close() end
 end
@@ -37,7 +38,7 @@ function load_from_file(infile)
 end
 
 function save_to_disk(State)
-  local outfile = App.open_for_writing(State.filename)
+  local outfile = App.open_for_writing(App.save_dir..State.filename)
   if outfile == nil then
     error('failed to write to "'..State.filename..'"')
   end