lua-users home
lua-l archive

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

In my format option spec (Oct. 20, 9:23 blog above), I extended the table
formatting options t, T, |(pre-char for index part), :(pre-char for key
part), *(pre-char for index+key part).

Further I specifed q(=q1) to be used for boolean values, and Q(=Q1) for int

E. g. if t is a boolean table, then you can use the following commands for
optimum packing:
string.pack( "|q", t)   (for the index part of t)
string.pack( ":q", t)   (for the key part of t)
string.pack( "*q", t)   (for the key part of t)

Further these "linear table format options (t, |, :, *) (NOT the nested
option T) will allow very easy de-composition of tables into key lists:
str_kv= string.pack( ":N", t)  (or "t2" instead of ":N", this is equivalent)
can then be very easily split into two indexed tables of keys and values:
t_keys, t_values= string.unpack( "|N|N", str)

... this is somehow a nice and powerful new application for pack and unpack,
which hopefully many people will love.

Sent from: