SpaceBeeGaming 3 Posted October 29, 2018 Share Posted October 29, 2018 I wrote this simple library for saving and loading tables from files as I needed such functionality for my program. (Useful for saving program settings between reboots.) Requirements: OpenOS Documentation: load(string: path) Returns the table stored in given path. save(table, string: path) Saves the table in a file located in path local serialization = require("serialization") local tableToFile = {} function tableToFile.load(location) --returns a table stored in a file. local tableFile = assert(io.open(location)) return serialization.unserialize(tableFile:read("*all")) end function tableToFile.save(table, location) --saves a table to a file local tableFile = assert(io.open(location, "w")) tableFile:write(serialization.serialize(table)) tableFile:close() end return tableToFile Usage: local ttf=require("tableToFile") --Saving local data={"a","b"} ttf.save(data,"/tmp/dataTable.txt") --loading local data=ttf.load("/tmp/dataTable.txt") If you have suggestions on how to improve it, please comment. (or make a pull request/issue in the GitHub repo.) This can also be found from here: https://github.com/SpaceBeeGaming/OC-Script-Collection/blob/master/lib/tableToFile.lua Quote Link to post Share on other sites