We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 43bcef5 commit 7bec11cCopy full SHA for 7bec11c
ludobits/m/savefile.lua
@@ -34,9 +34,16 @@ function M.open(filename)
34
--- Save table to the file
35
-- @param t The table to save
36
-- @return success
37
+ -- @return error_message
38
function instance.save(t)
39
assert(t and type(t) == "table", "You must provide a table to save")
- 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)
47
end
48
49
return instance
0 commit comments