lua-users home
lua-l archive

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


> In the  baseline, this  is a marshalling
> solution like in  ruby.  Not very elegant,
> but it works. Of course I would like some
> solution which is more lua'ish.

Lua is very adaptable to serialization constructs.  If you are very
interested then check the Wiki for "serialization", "XML", "tostring", and
probably several other key phrases dealing with particular representation
standards would be good things to search for.

Lua's table structure translates well to hiearchical data representations.
Userdata and tables with metatables present some complications that I
imagine different people have come up with fairly different approaches to
handling.  Recursive references slow things down slightly and cause some
slight extra memory consumption in the serialization process, but are easy
to overcome using Lua.  To overcome recursive references one just needs to
introduce an extra "type" into the stream representing references to objects
serialized earlier in the stream.  Constructing these references during the
serialization process or extracting them during the deserialization process
simply requires the formation of a table of already processed objects.
Since Lua can use any object/value as a table key you don't have to write
any table searching code yourself.  Just use the objects being serialized as
the keys when serializing, and the reference values as keys when
deserializing.