lua-users home
lua-l archive

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


On Mon, Apr 8, 2013 at 1:40 PM, Spencer Parkin
<spencerparkin@outlook.com> wrote:
> Am I making any sense here?  It seems like if I've got the Lua table on the
> stack, then I'm just a short distance away from being able to somehow call
> lua_dump to write it out to a file.  I'm just not sure how to create the Lua
> function.
>
> Also, does lua_dump somehow support the "mode" feature that lua_load does?
> Can lua_dump write out human readable Lua code, or is it alway going to be
> binary?


lua_dump() is not the complement to lua_load(), even if lua_load() can
read what is produced by lua_load().  You can say that lua_load() is
more generic than lua_dump(), the latter handles only bytecode, not
source code, not table data, nor the function environment.

Lua doesn't include any table serializer code, because there are many
slightly different ways to understand what should a serializer do.  In
the simplest case, it's just a 5-to-10-lines recursive function.

yes, there are several serializers available,  some of them in the
wiki.  If you don't want to download and require an external package,
just read a few of them and write your own.  A simple serializer for
non-cyclic structures shouldn't take more than half an hour.  a
reasonable complex one could be done in an afternoon.  If you want to
store functions, closures (and their upvalue context) that are stored
in a table, better bite the bullet and use a packaged library, like
Pluto (http://lua-users.org/wiki/PlutoLibrary).  Disclaimer: I haven't
used it, and don't know if it works with 5.2, or not

cheers,

--
Javier