[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: serialization nil values
- From: Markus Huber <pulse@...>
- Date: Wed, 29 Jan 2003 15:39:05 +0100 (GMT)
I am writing a function to serialize values:
function Serialize.ToString(...)
Thank you very much Roberto for the chapter 12.1. PERSISTENCE.
But I don't like to name the variables at this stage and I prefer to
serialize variable arguments at once.
To accept also cycles I use the following system
a={[8]=10,20}
b=0
c=''
d=true
e=false
String=Serialize.ToString(a,b,c,d,e)
print(String) --> local Table = {}
Table[1]={}
Table[1][1]=20
Table[1][8]=10
Table[2]=0
Table[3]=""
Table[4]=true
Table[5]=false
return unpack(Table)
The other side returns the perfect data:
Serialize.FromString(String)
loadstring(String)()
end
So I can read at this point wich variables are expected:
local a,b,c,d,e = Serialize.FromString(String)
Works fine until now. But:
a={[8]=10,20}
b=nil --> !
c=''
d=true
e=false
String=Serialize.ToString(a,b,c,d,e)
print(String) --> local Table = {}
Table[1]={}
Table[1][1]=20
Table[1][8]=10
Table[2]=nil
Table[3]=""
Table[4]=true
Table[5]=false
return unpack(Table)
Returns only the variable a. Because unpack() can't know that I need
a return of a nil too. Table[2] is defined as nil and so doesn't exist
to unpack. Also c,d and e are missing.
>From the Lua documentation: "The number n of returned values is either
the value of Table.n, if it is a number, or one less the index of the
first absent (nil) value."
Any tips and ideas to solve this problem are welcome.
Possible: return unpack(),nil,unpack() :-(
Or internal generated real variable names for each received argument?
local _1[1]={}
_1[1][1]=20
_1[1][8]=10
local _2[2]=nil
local _3[3]=""
local _4[4]=true
local _5[5]=false
return _1,_2,_3,_4,_5
Or what else?
Thank you.
--
Markus