-- eLua reference manual - pack data_en = { -- Title title = "eLua reference manual - pack", -- Menu name menu_name = "pack", -- Overview overview = [[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 ^http://www.tecgraf.puc-rio.br/~~lhf/ftp/lua/#lpack^lpack^ module from Luiz Henrique de Figueiredo (with some minor tweaks).
Both methods of this module (@#pack@pack@ and @#unpack@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]<where:
Format specifier | Corresponding variable type |
---|---|
'z' | zero-terminated string |
'p' | string preceded by length byte |
'P' | string preceded by length word |
'a' | string preceded by length size_t |
'A' | string |
'f' | float |
'd' | double |
'n' | Lua number |
'c' | char |
'b' | byte = unsigned char |
'h' | short |
'H' | unsigned short |
'i' | int |
'I' | unsigned int |
'l' | long |
'L' | unsigned long |
]], -- Functions funcs = { { sig = "packed = #pack.pack#( format, val1, val2, ..., valn )", desc = "Packs variables in a string.", args = { "$format$ - format specifier (as described @#overview@here@).", "$val1$ - first variable to pack.", "$val2$ - second variable to pack.", "$valn$ - nth variable to pack.", }, ret = "$packed$ - a string containing the packed representation of all variables according to the format." }, { sig = "nextpos, val1, val2, ..., valn = #pack.unpack#( string, format, [ init ] )", desc = "Unpacks a string", args = { "$string$ - the string to unpack.", "$format$ - format specifier (as described @#overview@here@).", "$init$ - $(optional)$ marks where in $string$ the unpacking should start (1 if not specified)." }, ret = { "$nextpos$ - the position in the string after unpacking.", "$val1$ - the first unpacked value.", "$val2$ - the second unpacked value.", "$valn$ - the nth unpacked value." } } }, } data_pt = data_en