serpent-serializer
Serialize Lua values to round-trippable Lua source, and load that source back.
The output is Lua source code that Lua's load reads into an equivalent value
graph. It preserves shared references, reconstructs cyclic references, emits
arrays positionally, uses short notation for identifier keys, and writes the
special numbers as 1/0, -1/0, and 0/0.
Installation
[]
= "0.1"
Entry points
dumpproduces full serialization wrapped in ado ... return _ endblock with a self-reference section. Compact and sparse by default.lineproduces single-line output. It is an expression, so prependreturnto evaluate it.loaddoes this for you.blockproduces multi-line indented output. Also an expression.serializeis the raw entry point that takes options as given.loadparses serialized output back into aValue.
Example
use ;
use ;
let t = new;
t.push;
t.push;
t.set;
let src = block.unwrap;
let back = load.unwrap;
assert!;
Options
Build options over Options::dump, Options::line, or Options::block, then
override the fields you need. Supported options include name, indent,
compact, sparse, fatal, maxnum, maxlevel, maxlength, nocode,
nohuge, comment, sortkeys, a custom sort, metatostring, numformat, the
value and key ignore filters, and a custom table formatter.
Safety
load runs in a sandbox by default. Any function call in the input is rejected
with "cannot call functions", and any global read or assignment resolves against
the sandbox, so it cannot reach real state. Set safe to Some(false) to
disable the call check.
Functions do not round-trip. The default output reloads a function through a
call, which the sandbox rejects, and load cannot run function bodies in any
case. Set nocode to emit an empty stub instead, which loads back as nil.
License
Licensed under the MIT license.