-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Integrate Lua with C++
By :

The Lua registry is a global table that can be accessed by all C/C++ code. It is one of the places that C++ code can keep state across different function calls. You cannot access this table in Lua code unless you use the Lua debug library. However, you should not use the debug library in production code; so, the registry is for C/C++ code only.
The registry versus upvalues
In the previous chapter, we learned about Lua upvalues. An upvalue keeps a state for a specific Lua C function across calls. The registry, on the other hand, can be accessed by all Lua C functions.
To export C++ types to Lua, we will use Lua userdata to represent the type and the registry so that we have a metatable for functions for the type. We will learn about the registry first, then the userdata, and finally put everything together to export C++ types to Lua.
Let’s add support for the registry in our Lua executor so that we know how to use it.