Simple data serializer for Lua 5.0+
Added support for unserializable data export. | 6bfc280, 25 Oct 2019 |
---|---|
LICENSE.md | |
README.md | |
serialize.lua | |
serialize.spec.lua |
serialize.lua
Simple data serializer for Lua 5.0 and higher.
Usage
local serialize = require('serialize')
serialize({ true, "hello", 5 })
Results in:
{
true,
"hello",
5,
}
Nested, indexed, associative (or both indexed and associative) tables are supported (and properly indented) as well as all primitive types. Strings are safely escaped using native string.format('%q')
.
You can create simple serialization to file like this:
file:write('return ' .. serialize(data))
Load serialized data by simply calling require
on the file or use load
(or loadstring
).
Attempting to serialize a function results in an error.
See serialize.spec.lua file for more examples.