about summary refs log tree commit diff stats
path: root/main.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-16 18:46:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-16 18:46:27 -0700
commit753318f664cb7c86b9c7e50e6ca79b68e4a02b60 (patch)
treeada0d9b0fb44d6698ff1b72329d3c87f7c55e1e7 /main.lua
parent662096d98fa5221e79c770d66e332d656a85ee8d (diff)
downloadtext.love-753318f664cb7c86b9c7e50e6ca79b68e4a02b60.tar.gz
gracefully handle a non-existent filename at the commandline
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua7
1 files changed, 5 insertions, 2 deletions
diff --git a/main.lua b/main.lua
index 826dfc5..80b0bfe 100644
--- a/main.lua
+++ b/main.lua
@@ -78,7 +78,7 @@ function love.draw()
   love.graphics.setColor(1, 1, 1)
   love.graphics.rectangle('fill', 0, 0, screenw-1, screenh-1)
   love.graphics.setColor(0, 0, 0)
-  local text
+  local text = love.graphics.newText(love.graphics.getFont(), '')
   local y = 0
   for i,line in ipairs(lines) do
     y = y+25
@@ -814,7 +814,7 @@ function math.dist(x1,y1, x2,y2) return ((x2-x1)^2+(y2-y1)^2)^0.5 end
 function load_from_disk(filename)
   local infile = io.open(filename)
   local result = load_from_file(infile)
-  infile:close()
+  if infile then infile:close() end
   return result
 end
 
@@ -832,6 +832,9 @@ function load_from_file(infile)
       end
     end
   end
+  if #result == 0 then
+    table.insert(result, '')
+  end
   return result
 end