A perf test against the trusted pickle function shows it is 0.114 seconds slower (across 10,000 iterations) and produces a string 0.8 times the size of pickle.
This function is only a curiosity. I can't say it is fool proof but tests have been positive so far, and the output is pleasantly readable.
example output
this table
Code: Select all
local alice = { name="Alice", balance=100 }
local bob = { name="Bob \"the coder\"", balance=-42 }
local financials = {
["version"] = 42,
["accounts"] = { alice, bob },
["transactions"] = {
{ account=alice, amount=50 },
{ account=alice, amount=40 },
{ account=alice, amount=10 },
{ account=bob, amount=-20 },
{ account=bob, amount=-20 },
{ account=bob, amount=-2 }
}
}
Code: Select all
00,accounts,version,transactions
00,1,2
00,1,2,3,4,5,6
00,name,balance
00,name,balance
00,amount,account
00,amount,account
00,amount,account
00,amount,account
00,amount,account
00,amount,account
01,[02],42,[03]
02,[04],[05]
03,[06],[07],[08],[09],[10],[11]
04,Alice,100
05,"Bob ""the coder""",-42
06,50,[04]
07,40,[04]
08,10,[04]
09,-20,[05]
10,-20,[05]
11,-2,[05]