-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On newer Minetest servers, handles saving jobs in async environment. To prevent conflicts, the save file is locked whie saving, and if a code requests saving while the file is locked, data is saved again immediately after finishing the current save.
- Loading branch information
Showing
3 changed files
with
74 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local areas = {} | ||
local core = core | ||
|
||
local safe_file_write = core.safe_file_write | ||
if safe_file_write == nil then | ||
function safe_file_write(path, content) | ||
local file, err = io.open(path, "w") | ||
if err then | ||
return err | ||
end | ||
file:write(content) | ||
file:close() | ||
end | ||
end | ||
|
||
-- Save the areas table to a file | ||
function areas:do_save(areas_tb, filename) | ||
local datastr = core.write_json(areas_tb) | ||
if not datastr then | ||
core.log("error", "[areas] Failed to serialize area data!") | ||
return | ||
end | ||
return safe_file_write(filename, datastr) | ||
end | ||
|
||
_G.areas = areas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters