diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-08-23 13:11:52 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-08-23 13:12:24 -0700 |
commit | 019a8292793077106b9b6927b9ca727918fad9ec (patch) | |
tree | 06eff3efb545bb7e6de0c71914cf2abac841c90e | |
parent | b6f42ebf01b6738458b37ff255f55854dea20adc (diff) | |
download | view.love-019a8292793077106b9b6927b9ca727918fad9ec.tar.gz |
make App.open_for_* look more like io.open
Now missing files will result in similar behavior: nil file handles.
-rw-r--r-- | app.lua | 16 |
1 files 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() |