I'm writing a C++/OOP wrapper for Lua. My code is:
class LuaState
{
boost::shared_ptr<lua_State> L;
LuaState(): L( luaL_newstate(), LuaState::CustomDeleter )
{
}
}
The problem is lua_State is incomplete type and shared_ptr constructor requires complete type. And I need safe pointer sharing. (Funny thing boost docs say most functions do not require complete type, but constructor requires, so there is no way of using it. http://www.boost.org/doc/libs/1_42_0/libs/smart_ptr/smart_ptr.htm)
Can can I solve this? Thank you.
You are using your own deleter, which means that you don't have to have a complete type upon construction. The only requirement is that CustomDeleter
can handle that. (it may convert the pointer passed to a complete type, for example (say, from void*
to CompleteType*
).
The background of completeness is that once the constructor of shared_ptr
is called with the default deleter, it will instantiate a class that contains the line delete p;
- and for this code to be correct, p
must not be incomplete. The destructor will call this deleter code indirectly, so it doesn't depend on the completeness of the type.
However if you pass your own deleter, the requirements of your own deleter will apply. Be sure to define CustomDeleter
after lua_State
has become completed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With