pack
A library for packing and unpacking binary data.
Supported letter codes:
This library was made by Luiz Henrique de Figueiredo (lhf@tecgraf.puc-rio.br) with contributions from Ignacio CastaƱo (castanyo@yahoo.es) and Roberto Ierusalimschy (roberto@inf.puc-rio.br). Original library can be found here.
require"pack"
local bindata = string.pack("zf", "foo", 4.2)
local mystring,myfloat = string.unpack(bindata, "zf")
pack
pack.pack(F, x1) | Pack binary data into a string. |
pack.unpack(s, F, init) | Unpacks a binary string into values. |
pack
pack.pack(F, x1)
F
:
a string describing how the values x1, x2, ... are to be interpreted and formatted.
Each letter in the format string F consumes one of the given values.
x1
:
x2, ... : variable number of values. Only values of type number or string are accepted.
a (binary) string containing the values packed as described in F.
require"pack"
local bindata = string.pack("zf", "foo", 4.2)
pack.unpack(s, F, init)
s
:
is a (binary) string containing data packed as if by pack
F
:
is a format string describing what is to be read from s
init
:
optional init marks where in s to begin reading the values
require"pack"
local _,mystring,myfloat = string.unpack(bindata, "zf")