lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Nov 10, 2009, at 10:44 AM, Wesley Smith wrote:

I'm sure everyone on this list has written a table serializer at some point.

Me too! Me too! :P

http://dev.alt.textdrive.com/browser/HTTP/Data.lua

Mostly based on Programming in Lua, 12.1.2 - Saving Tables with Cycles:

http://www.lua.org/pil/12.1.2.html

More alternatives:

http://lua-users.org/wiki/TableSerialization

Usage example for Data.lua:

local Data = require( 'Data' )

local a = {x = 1, y = 2, {3, 4, 5}}
a[2] = a -- cycle
a.z = a[1] -- shared subtable
a.f = function(n) return n+1 end

-- cross refs
local b = {k = a[1]}
a[3] = b

print( Data( a ) )


_[1]={}
_[1][1]=3
_[1][2]=4
_[1][3]=5
_[2]=_
_[3]={}
_[3]["k"]=_[1]
_["y"]=2
_["x"]=1
_ ["f "]= f "1b4c756151000104040408000e0000004054657374446174612e6c7561000a0000000a00000000010002030000004c0040005e0000011e0080000100000003000000000000f03f00000000030000000a0000000a0000000a00000001000000020000006e00000000000200000000000000 "
_["z"]=_[1]