Library for Converting Data to and from C Structs for Lua 5.0

This library offers basic facilities to convert Lua values to and from C structs. Its main functions are struct.pack, which packs multiple Lua values into a struct-like string; and struct.unpack, which unpacks multiple Lua values from a given struct-like string.

The fist argument to both functions is a format string, which describes the layout of the structure. The format string has the following syntax:

Lua API

All functions are registered inside a table struct.

Installing

To install, simply compile the file struct.c as a dynamic library. In Linux you can use the following command:
> gcc -Wall -O2 -shared -o struct.so struct.c
In Mac, you should define the environment variable MACOSX_DEPLOYMENT_TARGET as 10.3 and then write
> gcc -bundle -undefined dynamic_lookup -Wall -O2 -o struct.so struct.c

In Windows, you must generate a DLL exporting the single symbol luaopen_struct.

Examples