3.18 – Registry

Lua provides a registry, a pre-defined table that can be used by any C code to store whatever Lua value it needs to store, specially if the C code needs to keep that Lua value outside the life span of a C function. This table is always located at pseudo-index LUA_REGISTRYINDEX. Any C library can store data into this table, as long as it chooses keys different from other libraries. Typically, you should use as key a string containing your library name or a light userdata with the address of a C object in your code.

The integer keys in the registry are used by the reference mechanism, implemented by the auxiliary library, and therefore should not be used by other purposes.