From 019a8292793077106b9b6927b9ca727918fad9ec Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 23 Aug 2022 13:11:52 -0700 Subject: [PATCH] make App.open_for_* look more like io.open Now missing files will result in similar behavior: nil file handles. --- app.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app.lua b/app.lua index 9bf5e6a..cac1303 100644 --- a/app.lua +++ b/app.lua @@ -302,13 +302,15 @@ function App.open_for_writing(filename) end function App.open_for_reading(filename) - return { - lines = function(self) - return App.filesystem[filename]:gmatch('[^\n]+') - end, - close = function(self) - end, - } + if App.filesystem[filename] then + return { + lines = function(self) + return App.filesystem[filename]:gmatch('[^\n]+') + end, + close = function(self) + end, + } + end end function App.run_tests()