Skip to content

Commit 7bec11c

Browse files
author
Björn Ritzl
committed
savefile.lua was broken
1 parent 43bcef5 commit 7bec11c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ludobits/m/savefile.lua

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ function M.open(filename)
3434
--- Save table to the file
3535
-- @param t The table to save
3636
-- @return success
37+
-- @return error_message
3738
function instance.save(t)
3839
assert(t and type(t) == "table", "You must provide a table to save")
39-
sys.save(tmpfile, t)
40+
local tmpname = os.tmpname()
41+
local success = sys.save(tmpname, t)
42+
if not success then
43+
return false, "Unable to save file"
44+
end
45+
os.remove(path)
46+
return os.rename(tmpname, path)
4047
end
4148

4249
return instance

0 commit comments

Comments
 (0)