serialization

classic Classic list List threaded Threaded
17 messages Options
pau
Reply | Threaded
Open this post in threaded view
|

serialization

pau
Hi the list,

Is there a serialization/de-serialization function in Lua?
I've briefly looked at the source code, the only thing I
found close is dump and undump, and dump only exists in
luac. I suppose they are for dumping and loading chunks
(data, codes, stacks & all) only?

I am planning to use Lua in a network environment, which
involves passing data around. Since Lua supports complex
datatype - table, I wonder if there is any convinient (or
even built-in) function to save a table onto a stream and
then load it back? It will be even better if this feature
is platform & endian independent.

If there isn't any, would anyone know where I shall start
from?

Thanks in advance!

Regards,
Paul H. LIU

Reply | Threaded
Open this post in threaded view
|

Re: serialization

Alex Sandro Queiroz e Silva
On Mon, 16 Oct 2000 [hidden email] wrote:

> If there isn't any, would anyone know where I shall start
> from?
> 

Hallo,
	There is not such thing AFAIK, but it would be nice to have a
library (in Lua) to convert tables (or environments) to XML for
distributed systems. What about that?

  --Alex	[hidden email]		Lab. de Computação Gráfica/UFC
+----------------------------------------------------------------------------+
|"Minha força vem da solidão. Não tenho medo das chuvas tempestuosas nem das |
| grandes ventanias soltas, pois eu também sou o escuro da noite."	     |
|	- Clarice Lispector						     |
+----------------------------------------------------------------------------+


Reply | Threaded
Open this post in threaded view
|

Re: serialization

Daniel Silverstone-2
In reply to this post by pau
On Mon, 16 Oct 2000 [hidden email] wrote:

[snip serialisation question]

I am planning a function to write a table out as Lua to recreate it,
as part of my configuration system. Would that be useful to you?
If so, I'll set about writing it tonight.

Daniel

-- 
Daniel Silverstone                            Tel: +44 1223 525000
Global Services Engineer                      Fax: +44 1223 525100
Zeus Technology Ltd                           http://www.zeus.com/
Zeus House, St John's Innovation Park, Cowley Road CB4 0ZT England


Reply | Threaded
Open this post in threaded view
|

Re: serialization

Luiz Henrique de Figueiredo
In reply to this post by pau
>I am planning a function to write a table out as Lua to recreate it,
>as part of my configuration system. Would that be useful to you?

Sample code for this already exists at lua/test/save.lua.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: serialization

John Belmonte-2
In reply to this post by pau
Steve Dekorte had something along those lines already written.  See this
message in the mailing list archives:

  Sent: Saturday, April 22, 2000 5:43 AM
  Subject: Pickle

However his web site seems to be down... Steve?



Reply | Threaded
Open this post in threaded view
|

Re: serialization

Daniel Silverstone-2
In reply to this post by Luiz Henrique de Figueiredo
On Mon, 16 Oct 2000, Luiz Henrique de Figueiredo wrote:

>>I am planning a function to write a table out as Lua to recreate it,
>>as part of my configuration system. Would that be useful to you?
>
>Sample code for this already exists at lua/test/save.lua.

Unfortunately if you alter the code to call save() twice, the second
time, it serialises:

-- global environment
b=b
x=x
a=3
PI=3.141592653589793
_VERSION="Lua 4.0 (beta)"

----END

I.E. it fails to serialise the same structure more than once.
Not good.

Also, it relies on being able to insert __visited__ into each table.
I personally don't want that, hence I'm writing my own, using
a set of elements etc.

Regards,

Daniel

-- 
Daniel Silverstone                            Tel: +44 1223 525000
Global Services Engineer                      Fax: +44 1223 525100
Zeus Technology Ltd                           http://www.zeus.com/
Zeus House, St John's Innovation Park, Cowley Road CB4 0ZT England


Reply | Threaded
Open this post in threaded view
|

Re: serialization

Luiz Henrique de Figueiredo
In reply to this post by pau
>Unfortunately if you alter the code to call save() twice, the second
>time, it serialises:
>I.E. it fails to serialise the same structure more than once.
>Not good.
>
>Also, it relies on being able to insert __visited__ into each table.
>I personally don't want that, hence I'm writing my own, using
>a set of elements etc.

You're right. Like I said, this is *sample* code.
A much better solution is to create a table (local to the chunk) that keeps
tracks of the __visited__ elements.
I'll change save.lua to do that for 4.0 final.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: serialization

Daniel Silverstone-2
On Mon, 16 Oct 2000, Luiz Henrique de Figueiredo wrote:

>You're right. Like I said, this is *sample* code.
>A much better solution is to create a table (local to the chunk) that keeps
>tracks of the __visited__ elements.
>I'll change save.lua to do that for 4.0 final.

If you're going to do that, then I'll wait a couple of weeks, and get on with
my extensions like postgresql and pcre in Lua 4.0beta.

Just to confirm - there are no major API changes planned for 4.0final are
there?

Daniel.


-- 
Daniel Silverstone                            Tel: +44 1223 525000
Global Services Engineer                      Fax: +44 1223 525100
Zeus Technology Ltd                           http://www.zeus.com/
Zeus House, St John's Innovation Park, Cowley Road CB4 0ZT England


Reply | Threaded
Open this post in threaded view
|

Re: serialization

Luiz Henrique de Figueiredo
In reply to this post by pau
>Just to confirm - there are no major API changes planned for 4.0final are
>there?

No, there should be no changes at all in the API.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: serialization

Roberto Ierusalimschy
> >Just to confirm - there are no major API changes planned for 4.0final are
> >there?

> No, there should be no changes at all in the API.

Besides those small ones already announced in the list (lua_type and
lua_collectgarbage).

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: serialization

sued
In reply to this post by Luiz Henrique de Figueiredo
On Mon, Oct 16, 2000 at 11:17:20AM -0200, Luiz Henrique de Figueiredo wrote:
> >I am planning a function to write a table out as Lua to recreate it,
> >as part of my configuration system. Would that be useful to you?
> 
> Sample code for this already exists at lua/test/save.lua.

Thanks. But I am looking for a C level implementation which preferably 
saves the thing much faster and compact without involving operation 
on stack.

Regards,
.paul.

Reply | Threaded
Open this post in threaded view
|

Re: serialization

Rob Kendrick-4
In message <20001017002713.A15121@...> you wrote:
X-Editor: Zap, using ZapEmail 0.23 (11 Feb 1999) alpha-4
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

> On Mon, Oct 16, 2000 at 11:17:20AM -0200, Luiz Henrique de Figueiredo wrote:
> > >I am planning a function to write a table out as Lua to recreate it,
> > >as part of my configuration system. Would that be useful to you?
> > 
> > Sample code for this already exists at lua/test/save.lua.
> 
> Thanks. But I am looking for a C level implementation which preferably 
> saves the thing much faster and compact without involving operation 
> on stack.

Wait for Daniel's then.  If it wasn't for two very drunken ladies who
are currently staying with us, he'd prolly do it this evening :)

Cheers,
-- 
Rob Kendrick

Reply | Threaded
Open this post in threaded view
|

Re: serialization

Daniel Silverstone-2
In reply to this post by sued
[hidden email] wrote:

> On Mon, Oct 16, 2000 at 11:17:20AM -0200, Luiz Henrique de Figueiredo wrote:
> > >I am planning a function to write a table out as Lua to recreate it,
> > >as part of my configuration system. Would that be useful to you?
> >
> > Sample code for this already exists at lua/test/save.lua.
>
> Thanks. But I am looking for a C level implementation which preferably
> saves the thing much faster and compact without involving operation
> on stack.

Umm, Surely as of Lua 4.0 you'd need to use the stack to do anything with
Lua data. Full Stop?

If you can come up with something, then let us all know..

Daniel



Reply | Threaded
Open this post in threaded view
|

Re: serialization

Steve Dekorte-6
In reply to this post by pau
On Monday, October 16, 2000, at 06:21 AM, John Belmonte wrote:

> Steve Dekorte had something along those lines already written.  See this 
> message in the mailing list archives: 
>  
>   Sent: Saturday, April 22, 2000 5:43 AM 
>   Subject: Pickle 
>  
> However his web site seems to be down... Steve? 

I'm switching DSL providers at the moment, so the site will be down for a while, but I do have a package for that.
For now, I can mail it to anyone that's interested.

Btw, maybe an anonymous ftp server at Tecgraf would be a good long term repository for open source lua code?

Steve

Reply | Threaded
Open this post in threaded view
|

RE: serialization

Ignacio Castano
Steve Dekorte wrote:
> Btw, maybe an anonymous ftp server at Tecgraf would be a good long term repository for open source
> lua code?

yes, that's a good idea.


Ignacio Castano
[hidden email]





Reply | Threaded
Open this post in threaded view
|

Re: serialization

John Belmonte-2
In reply to this post by Steve Dekorte-6
> Btw, maybe an anonymous ftp server at Tecgraf would be a good long term
repository
>  for open source lua code?

Don't forget that lua-l's eGroups files repository is also available.



Reply | Threaded
Open this post in threaded view
|

XML

YutakaUeno
In reply to this post by Alex Sandro Queiroz e Silva
Alex Sandro Queiroz e Silva wrote :
>library (in Lua) to convert tables (or environments) to XML for
>distributed systems. What about that?

Yes, I agree. Since Lua is powerful enough to handle XML files,
a guideline for table usage would be helpful for people to share
programs. I think we can simplify a method proposed in this 
mailing list by Roberto <[hidden email]>:

                   <section link="hi">
                      <title>Hello</title>
                      This is only a text <ldots/> and more text
                    </section>

                    will result in a tree like

                    { xml = "section", link="hi";
                      { xml = "title"; "Hello"},
                      "This is only a text ",
                      { xml = "ldots"},
                      " and more text"
                    }

Because, the name "xml" never appears in attribute names in a tag,
the tag name is described as a property "xml". It simplifies the result 
tree.
My experimental code is http://www.etl.go.jp/~ueno/lua/test/

---ueno