diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-08-30 22:45:37 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-08-30 22:45:37 -0700 |
commit | 1fc11feb28bf336f9a1d74e014ad4c7418001047 (patch) | |
tree | a1dd933af786edcb1cc8341b55c513093349b9a4 /source_file.lua | |
parent | e1fcd7c9c37a81c6198a2162b6348fe595ef21d5 (diff) | |
parent | 06ad5c4e8ce1c4a78db7eb11b680758fab68cc69 (diff) | |
download | view.love-1fc11feb28bf336f9a1d74e014ad4c7418001047.tar.gz |
Merge lines.love
Diffstat (limited to 'source_file.lua')
-rw-r--r-- | source_file.lua | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/source_file.lua b/source_file.lua index 3eaf6c3..b0e26eb 100644 --- a/source_file.lua +++ b/source_file.lua @@ -1,7 +1,10 @@ -- primitives for saving to file and loading from file function file_exists(filename) - local infile = App.open_for_reading(filename) + local infile = App.open_for_reading(App.save_dir..filename) + if not infile then + infile = App.open_for_reading(App.source_dir..filename) + end if infile then infile:close() return true @@ -10,8 +13,12 @@ function file_exists(filename) end end +-- the source editor supports only files in the save dir backed by the source dir function load_from_disk(State) - local infile = App.open_for_reading(State.filename) + local infile = App.open_for_reading(App.save_dir..State.filename) + if not infile then + infile = App.open_for_reading(App.source_dir..State.filename) + end State.lines = load_from_file(infile) if infile then infile:close() end end @@ -37,7 +44,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 |