Because of the ability to now register the sysExitEvent and sysLoadEvent functions, I've created table.LoadRelative() and table.saveRelative() to easily save and load tables relative to the mudlet home directory:
function table.SaveRelative(relPath, saveTable)
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local saveFile = getMudletHomeDir() .. _sep .. relPath
table.save(saveFile, saveTable)
end
Is it worth having something similar added to the lua globals file?
function table.saveRelative(relPath, saveTable)
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local saveFile = getMudletHomeDir() .. _sep .. relPath
table.save(saveFile, saveTable)
end
function table.loadRelative(relPath)
if string.char(getMudletHomeDir():byte()) == "/" then _sep = "/" else _sep = "\\" end
local saveFile = getMudletHomeDir() .. _sep .. relPath
local loadTable = {}
table.load(saveFile, loadTable)
return loadTable
end
function antitheft_save_tracked()
local saveTable = {
tracked = Antitheft.tracked,
container = Antitheft.container
}
table.saveRelative("antitheft.lua", saveTable)
end
function antitheft_load_tracked()
local loaded = table.loadRelative("antitheft.lua")
if loaded.tracked then
Antitheft.tracked = loaded.tracked
end
if loaded.container then
Antitheft.container = loaded.container
end
end