Original Post
Hi, I am working more with Lua, and exposing more of my C++ internals to Lua scripting. As part of this process I have a number of classes that need to be exposed to Lua - I am doing this using Luabind. My question is: How do you structure this exposure within C++? Each class that needs exposure requires a luabind::module call. The simplest way to do this would be to have a function do all this calling as part of the initialization process. However, this seems to me to be a large compile-time bottleneck - this one file needs to pull in the header files from each of the classes that needs to be exposed. This seems undesirable. I thought about using a static registration of the form: This works up to the point of needing inheritance, as one can't specify the order of static initializations. So - am I missing something, as I often do? Is there a simple (or even complex) solution to this problem? Or do I just need to suck it up and accept that I will be using one file to expose all my C++ classes? Thanks, Jim.
// .h file
struct MyClass
{
static bool RegisterWithLua();
};
// .cpp file
namespace
{
const bool registered = MyClass::RegisterWithLua();
}
bool MyClass::RegisterWithLua()
{
// Do the actual registration
}