Designing a type exporter
First, let us define our scope. We want to generalize the factory we have just made and make it work with any C++ class – that is, the C++ class still needs to implement and provide the lua_CFunction
wrappers in some way. It is possible to automate the creation of those wrappers, but that would require implementing a heavy C++ template library, which is not strictly related to Lua and is out of the scope of this book.
With the scope defined, let us make some high-level designs.
Choosing a design pattern
When we talk about making something general in C++, usually it means we need to use templates. To work with our Lua executor, we need to export LuaModule
. So, we need to implement the exporter as a template class that can provide LuaModule
.
How can we provide LuaModule
? We can make the exporter inherit from the LuaModule
interface, or make one of its member functions return LuaModule
.