Module: lib-tde.serialize
Serialize lua objects (tables) into a string and back
You can easily convert lua objects into a serialized representation This is useful for storing and restoring lua objects
serialize({1,2,3, {hello="world"}}) -- becomes "[1,2,3, {hello='world'}]" (string) deserialize("[1,2,3, {hello='world'}]") -- becomes {1,2,3, {hello="world"}} (table)
You can also save this data to a file serializetofile("file.json", {1,2,3}) -- serialize the data and send it to the file deserializefromfile("file.json") -- returns {1,2,3}
This module tries to improve re-usage of know variables throughout the tde infrastructure.
Info:
- Copyright: 2020 Tom Meyers
- Author: Tom Meyers
Static module functions
lib-tde.serialize.serialize (tbl) -> () | Serialize tables into a string representation | |
lib-tde.serialize.deserialize (str) -> () | Deserialize a string into a tables | |
lib-tde.serialize.serialize_to_file (tbl) | Serialize table and save it to a file | |
lib-tde.serialize.deserialize_from_file (file) -> () | Deserialize data found in a file |
Static module functions
- lib-tde.serialize.serialize (tbl) -> ()
-
Serialize tables into a string representation
Parameters:
- tbl table the table to serialize
Returns:
-
string The serialized representation of the lua object
Usage:
-- returns "[1,2,3,4, {hello='world'}]" lib-tde.serialize.serialize({1,2,3,4, {hello='world'}})
- lib-tde.serialize.deserialize (str) -> ()
-
Deserialize a string into a tables
Parameters:
- str string The string to deserialize into lua tables
Returns:
-
table The deserialized lua table
Usage:
-- returns {1,2,3,4, {hello='world'}} lib-tde.serialize.deserialize("[1,2,3,4, {hello='world'}]")
- lib-tde.serialize.serialize_to_file (tbl)
-
Serialize table and save it to a file
Parameters:
- tbl table the table to serialize
Usage:
-- saves to file lib-tde.serialize.serialize_to_file("file.json", {1,2,3,4, {hello='world'}})
- lib-tde.serialize.deserialize_from_file (file) -> ()
-
Deserialize data found in a file
Parameters:
- file string The path to the file to deserialize
Returns:
-
table The deserialized lua table
Usage:
-- Deserializes the content found in the file to lua tables local object = lib-tde.serialize.deserialize_from_file("file.json")