|
On May 18, 2007, at 19:31, Luis Carvalho wrote:
I've updated the pickler code with your suggestions and a few changes, andit's now in version 0.2. I can post it later (wiki?) if there's enough interest, or send the code privately.
Very nice. Would be interested to see the final version as well :)To follow the established tradition of "Lua gives you the power; you build the mechanisms" [1], here is yet another serialization process based on PiL1 [2]:
local Store = require( 'Store' ) 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 -- io.open( 'a.txt', 'wb' ):write( Store( a ) ) -- io.open( 'b.txt', 'wb' ):write( Store( b ) ) -------------------------------------- -- another time, another place -------------------------------------- a = Store( io.open( 'a.txt', 'rb' ):read( '*a' ) ) print( 'a.f', a.f( math.pi ) ) for aKey, aValue in pairs( a ) do print( aKey, aValue ) end b = Store( io.open( 'b.txt', 'rb' ):read( '*a' ) ) for aKey, aValue in pairs( b ) do print( aKey, aValue ) end [1] http://lua-users.org/wiki/LuaRecipes [2] http://www.lua.org/pil/12.1.2.html
Attachment:
Store.lua
Description: Binary data
Attachment:
a.txt
Description: Binary data
Attachment:
b.txt
Description: Binary data