This module allows for arbitrary packing of data into Lua strings and unpacking data from Lua strings. In this way, a string can be used to store data in a platform-indepdendent manner. It is based on the lpack module from Luiz Henrique de Figueiredo (with some minor tweaks).

Both methods of this module (pack and unpack) use a format string to describe how to pack/unpack the data. The format string contains one or more data specifiers, each data specifier is applied to a single variable that must be packed/unpacked. The data specifier has the following general format:

[endianness]<format specifier>[count]



packed = pack.pack( format, val1, val2, ..., valn )

Packs variables in a string.


Returns: packed - a string containing the packed representation of all variables according to the format.

nextpos, val1, val2, ..., valn = pack.unpack( string, format, [ init ] )

Unpacks a string