lua-users home
lua-l archive

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


> > 3. Tables should be checked for a serialization metamethod
> > just like userdata.
>
> right, of course...anything with a metatable should be able
> to use it for customizable persistence.
>
> My current idea was to have three possiblities for the
> metatable for userdata: mt.__persist==true, in which case
> it would be literally serialized like a string,
> mt.persist==function, returning the closure, or no value,
> indicating that the userdata may not be persisted.
> I'll probably do the same thing for tables, except that
> the default will allow literal persisting, requiring an
> explicit "false" value to prevent persistence.
> How's that sound?

Sounds ideal to me.  The "true" default for tables and "false" default for
heavy userdata balances things nicely.


> > 5. In my own serialization of heavy userdata I found it
> > necessary to add my own "special type" called a blob...
>
> Hmm... so what, then, was the difference between a blob
> and a heavy userdata?

Well I was using Lua4 and there were no "heavy" userdata.......  Um, you got
me.  A heavy userdata with "mt.__persist==true" would exactly fulfill the
role of my "blob".  To use this optimally a userdata would have to allocate
additional userdata's whenever it needed to use dynamic allocation of
internal members (which improves gc memory tracking anyway), but if userdata
operate this way -- and they don't need to do data compression/reformatting
for persistence -- then they completely avoid doing allocations and data
copies for persistence operations.

BTW: Did you have to go outside the API to get the size of a userdata?
(well I can pick that out from the code later).


<Historical Blather>
Userdata in Lua4 were just pointers (like light userdata) with tag (like
meta) methods, so there was no size information for userdata accessible
through Lua.  Secondly, the "blob type" (identified by its Lua4 "tag) was
known to the persistence system so when it encountered one it knew how to
determine the size of buffer of data to be persisted, and that it should
just do that literal persistence of the buffer rather than searching for a
"persistence metamethod".
</Historical Blather>