[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Serializing lua state.
- From: Björn De Meyer <bjorn.demeyer@...>
- Date: Wed, 11 Sep 2002 19:33:26 +0200
"Adam D. Moss" wrote:
> I was wondering if anyone out there has any experience or
> thoughts on serializing and deserializing the state of the
> lua environment to/from disk.
Well, that is not that difficult in lua. Check the
test/save.lua script of the lua-5.0-alpha source distrubution.
Basically, you use a for loop to walk over all Lua tables
that contain the variables you want to serialise, and use format()
to output that data to a file in lua format. To load your
file, simply use dofile() or such to re-import the data.
If cheating is an issue, then you might want to compile
the lua output file to bytecode, or compress it with zlib,
or cloak it by using some kind of roman cipher. Or,
use checksums or such. However, then, your procedure
to load the game will be a bit more difficult, though.
"No one knows true heroes, for they speak not of their greatness." --
Björn De Meyer