about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-23 13:11:52 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-23 13:12:24 -0700
commit019a8292793077106b9b6927b9ca727918fad9ec (patch)
tree06eff3efb545bb7e6de0c71914cf2abac841c90e
parentb6f42ebf01b6738458b37ff255f55854dea20adc (diff)
downloadtext.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.lua16
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()