Skip to content

Instantly share code, notes, and snippets.

@skrolikowski
Created December 6, 2020 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skrolikowski/34a33d5fe066e06e8b51dcf28b9c84c7 to your computer and use it in GitHub Desktop.
Save skrolikowski/34a33d5fe066e06e8b51dcf28b9c84c7 to your computer and use it in GitHub Desktop.
Save Module for Love2D
-- Binser is a lua serializer: https://github.com/bakpakin/binser
local Binser = 'vendor.binser.binser'
local Saver = {}
-- Write to save file
--
function Saver:save(name, data)
love.filesystem.write(name .. '.txt', Binser.serialize(data))
return data
end
-- Load save file
--
function Saver:load(name)
if self:exists(name) then
local data, size = love.filesystem.read(name .. '.txt')
return Binser.deserialize(data)[1]
end
return false
end
-- File exists?
--
function Saver:exists(name)
return self:getInfo(name) ~= nil
end
-- Get file info
--
function Saver:getInfo(name)
return love.filesystem.getInfo(name .. '.txt', 'file')
end
return Saver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment