[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.pack with bit resolution
- From: bil til <flyer31@...>
- Date: Thu, 24 Oct 2019 21:45:14 -0700 (MST)
Concerning the background info / motivation to go over the pack/unpack
function:
I hope we agree in the following points:
- pack-unpack should be capable to transfer data to/from different devices
(non-lua, or also lua32-lua64-(lua128))
- pack-unpack further should support tables as parameters, as in case of
much data it makes not much sense to use the "..." stack vaarg to transfer
data to the functions (much too restricted, too much effort to line up all
the values of a table)
- it will be very nice to have an N type, which supports ANY possible value
in lua (giving errors only for functions, userdata, threads, but supporting
besides lua_number (i+f)) also boolean, strings and sub-tables).
- further bit-packed integers should be included
- the target should be, that format string is the same for pack and unpack
of a specified data set, and that a table which is packed, will unpack as
far as possible to the same table (at least if it is a table with values…).
Therefore I want to use now the format string options for pack/unpack, as
defined in the previous blog. I tried to keep as much from your original
lua5.3 spec. But I really see no reason to support “native lua” there (as
this gives problems already lua32 <> lua64 – so I removed j, J, n, T, =, x
… but as a nice replacement you get N which supports “any lua value” in a
clearly defined way I one element), and also no reason to support alignment
other than 1 bit or 1 byte (1 bit only for q/Q …). (see the "2nd previous"
blog before for specification of N).
Some examples:
str= string.pack( “qqqQQQ 4Q3”, true, false, true, 1, 0, 1, 1, 3, 5,
7)
Some examples with tables:
str= string.pack( “T”, table1)
str= string.pack( “4T”, table1, table2, table3, table4)
str= string.pack( “t”, table1)
str= string.pack( “|q”, table_boolean1) -- packs boolean index table to
bits (optimum packing)
str= string.pack( “3|q”, table_boolean1, table_boolean2, table_boolean3)
str= string.pack( “100^q”, table_boolean1)
Nice “side-application”, to split a table into its index part, key part and
hash-values:
str= string.pack( “t”, table1)
table1_index, table1_keys, table1_values= string.unpack( str)
--
Sent from: http://lua.2524044.n2.nabble.com/Lua-l-f2524044.html
- References:
- Re: string.pack with bit resolution, bil til
- Re: string.pack with bit resolution, Sean Conner
- Re: string.pack with bit resolution, bil til
- Re: string.pack with bit resolution, Sean Conner
- Re: string.pack with bit resolution, bil til
- Re: string.pack with bit resolution, Sean Conner
- Re: string.pack with bit resolution, bil til
- Re: string.pack with bit resolution, Sean Conner
- Re: string.pack with bit resolution, bil til
- Re: string.pack with bit resolution, bil til