[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Saving a table in file
- From: "Luciano de Souza" <luchyanus@...>
- Date: Sun, 7 Mar 2010 16:47:58 -0300
If I understood: to serialize is to convert tables into a string
representation and, without some significant code, we cannot do it.
I will study everything you sent me. But now I need the simplest solution. I
am studying IUP. I am trying to save some data in a file to test more
realistically the features I programed. Up to now, the simplest way to save
tables, as I cold see, the way we write less lines, it seems to be using
XML. Am I right?
I only want to save a table. Firstly, I tried to use Sqlite3. I learnt the
SQL sintax. I read something about normalized databases. I read... I read...
But although Sqlite is really simple, something always is wrong. It seemed
to be very simple. But I got errors without error messages.
After I tried to use lots of coma separated files, but it became hard.
I tried to use XML and the results were OK to write values. To read values
semms to be a little bit harder. As I could see, the simplest way to store a
table is to use Luaxml.
Actually, I tried to create my tables in Pascal:
type
wolrd = record
country: string;
city: string;
end;
With Plua and the interface with Lua stack, I could add and remove values in
a table stored in a file. But it's a awful way, I know.
In Python, we have something like:
import shelve
file = shelve.open('countries.db')
For this point on, "file" can be used as a table. After trying so many
different things, only to save some data collected by a IUP interface,
perhaps I am impacient. I am not lazy, believe.
My options area:
1. to discover how to handle with the Sqlite erros;
2. to undestand better Luaxml. I found so few examples that I didn't mature
the idea. Lua has good manuals, but I think Luaxml is not one of then.
If I invest in this strategies of serialization, I will to learn more, and
more, and more... I know to learn is one of the best things in the wolrd,
but at this moment I need to conquer something.
That's the greatest problem of beginners. You are right in everything you
said. I think the problem is me.
----- Original Message -----
From: "Matthias Kluwe" <mkluwe@gmail.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Sunday, March 07, 2010 3:21 PM
Subject: Re: Saving a table in file
Hi!
2010/3/7 Luciano de Souza <luchyanus@predialnet.com.br>:
Hello,
Suppose we have the following table:
t =
{
{country = 'Brazil', city = 'São Paulo'},
{country = 'Italy', city = 'Napoli'},
{country = 'France', city = 'Nantes'},
{country = 'United States', city = 'Chicago'}
}
I know how to add or remove elements. But, how to save it in a file?
Your problem is known as "serialization"
(http://en.wikipedia.org/wiki/Serialization, someone may add a Lua
example here). Take a look at http://www.lua.org/pil/12.1.html or
http://lua-users.org/wiki/TableSerialization.
Regards,
Matthias