From 31266e23f5bbdf5887303bbcc0f69246e6e45f57 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 9 Sep 2023 08:27:27 -0700 Subject: [PATCH 1/4] reorder --- app.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app.lua b/app.lua index 8a7e0b2..03bc4de 100644 --- a/app.lua +++ b/app.lua @@ -273,17 +273,6 @@ end -- various Lua and LÖVE helpers, tests will be able to check the results of -- file operations inside the App.filesystem table. -function App.open_for_writing(filename) - App.filesystem[filename] = '' - return { - write = function(self, s) - App.filesystem[filename] = App.filesystem[filename]..s - end, - close = function(self) - end, - } -end - function App.open_for_reading(filename) if App.filesystem[filename] then return { @@ -299,6 +288,17 @@ function App.open_for_reading(filename) end end +function App.open_for_writing(filename) + App.filesystem[filename] = '' + return { + write = function(self, s) + App.filesystem[filename] = App.filesystem[filename]..s + end, + close = function(self) + end, + } +end + function App.mkdir(dirname) -- nothing in test mode end From bcd7f6b59828f6f5419c1a48394d12177ba35446 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 9 Sep 2023 08:56:21 -0700 Subject: [PATCH 2/4] new primitives for reading/writing files These are like versions in nativefs, but only support absolute paths. I want to be thoughtful about the precise location at each call-site. It's a little ugly that app.lua now has a dependency on file.lua. Or source_file.lua for the source editor. --- app.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app.lua b/app.lua index 03bc4de..b615ad0 100644 --- a/app.lua +++ b/app.lua @@ -288,6 +288,10 @@ function App.open_for_reading(filename) end end +function App.read_file(filename) + return App.filesystem[filename] +end + function App.open_for_writing(filename) App.filesystem[filename] = '' return { @@ -299,6 +303,11 @@ function App.open_for_writing(filename) } end +function App.write_file(filename, contents) + App.filesystem[filename] = contents + return --[[status]] true +end + function App.mkdir(dirname) -- nothing in test mode end @@ -435,6 +444,19 @@ function App.disable_tests() return ok, err end end + App.read = + function(path) + if not is_absolute_path(path) then + return --[[status]] false, 'Please use an unambiguous absolute path.' + end + local f, err = App.open_for_reading(path) + if err then + return --[[status]] false, err + end + local contents = f:read() + f:close() + return contents + end App.open_for_writing = function(filename) local result = nativefs.newFile(filename) @@ -445,6 +467,18 @@ function App.disable_tests() return ok, err end end + App.write = + function(filename, contents) + if not is_absolute_path(path) then + return --[[status]] false, 'Please use an unambiguous absolute path.' + end + local f, err = App.open_for_writing(filename) + if err then + return --[[status]] false, err + end + f:write(contents) + f:close() + end App.files = nativefs.getDirectoryItems App.mkdir = nativefs.createDirectory App.remove = nativefs.remove From 0016d668bcbd5a88afaaa305cddeff7a4300f215 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 9 Sep 2023 09:09:14 -0700 Subject: [PATCH 3/4] two bugfixes Annoying dangers of testing in one fork and committing upstream (where it isn't used yet). --- app.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app.lua b/app.lua index b615ad0..d4a2a70 100644 --- a/app.lua +++ b/app.lua @@ -444,7 +444,7 @@ function App.disable_tests() return ok, err end end - App.read = + App.read_file = function(path) if not is_absolute_path(path) then return --[[status]] false, 'Please use an unambiguous absolute path.' @@ -467,7 +467,7 @@ function App.disable_tests() return ok, err end end - App.write = + App.write_file = function(filename, contents) if not is_absolute_path(path) then return --[[status]] false, 'Please use an unambiguous absolute path.' @@ -478,6 +478,7 @@ function App.disable_tests() end f:write(contents) f:close() + return --[[status]] true end App.files = nativefs.getDirectoryItems App.mkdir = nativefs.createDirectory From 790b7f18dbfb6c7dfcc72a872bc62e6075af6ae8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 9 Sep 2023 09:27:56 -0700 Subject: [PATCH 4/4] yet another bugfix X-( This time it really does work with pensieve.love --- app.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.lua b/app.lua index d4a2a70..55b1b0d 100644 --- a/app.lua +++ b/app.lua @@ -468,11 +468,11 @@ function App.disable_tests() end end App.write_file = - function(filename, contents) + function(path, contents) if not is_absolute_path(path) then return --[[status]] false, 'Please use an unambiguous absolute path.' end - local f, err = App.open_for_writing(filename) + local f, err = App.open_for_writing(path) if err then return --[[status]] false, err end