lua-users home
lua-l archive

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


> I'd like to let Lua do the serialization for my game--it has access to
all
> the variables anyway so I thought it would be easy and robust to do a
> foreach on each of the tables and write them to disk.  Unfortunately it
> looks like the file I/O functions read and write only provide capability
for
> strings and numbers, NOT userdata. Is there a way around this?--or do I
need
> to write my own functions?

Yes, you have to write your own routines.

In Lua5beta, you can define a __tostring metamethod. This might help
appearances.

(How would you expect a programming language to guess how you wanted to
serialise a userdata? Many userdatas have random pointers in them which are
not going to serialise very well without help.)