about summary refs log tree commit diff stats
path: root/file.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-25 19:56:39 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-25 19:56:39 -0700
commit48162b981689c58e54ad44f45a9ba4b70a1c68d7 (patch)
tree8184b384917184e1553017b278602f9515d49f18 /file.lua
parente26470aada335d56c0766fb2e32524981a6e9af2 (diff)
downloadlines.love-48162b981689c58e54ad44f45a9ba4b70a1c68d7.tar.gz
have file API operate on state object
Diffstat (limited to 'file.lua')
-rw-r--r--file.lua15
1 files changed, 7 insertions, 8 deletions
diff --git a/file.lua b/file.lua
index c5946d6..9440ae8 100644
--- a/file.lua
+++ b/file.lua
@@ -1,9 +1,8 @@
 -- primitives for saving to file and loading from file
-function load_from_disk(filename)
-  local infile = App.open_for_reading(filename)
-  local result = load_from_file(infile)
+function load_from_disk(State)
+  local infile = App.open_for_reading(State.filename)
+  State.lines = load_from_file(infile)
   if infile then infile:close() end
-  return result
 end
 
 function load_from_file(infile)
@@ -26,12 +25,12 @@ function load_from_file(infile)
   return result
 end
 
-function save_to_disk(lines, filename)
-  local outfile = App.open_for_writing(filename)
+function save_to_disk(State)
+  local outfile = App.open_for_writing(State.filename)
   if outfile == nil then
-    error('failed to write to "'..filename..'"')
+    error('failed to write to "'..State.filename..'"')
   end
-  for _,line in ipairs(lines) do
+  for _,line in ipairs(State.lines) do
     if line.mode == 'drawing' then
       store_drawing(outfile, line)
     else