kunitoki / LuaBridge3

A lightweight, dependency-free library for binding Lua to C++
https://kunitoki.github.io/LuaBridge3/Manual
Other
253 stars 40 forks source link

Recent LB3 Change Causes my code not to compile. #155

Closed rpatters1 closed 1 year ago

rpatters1 commented 1 year ago

A recent change to LB3 has caused my code not to compile. Specifically, it fails because the copy constructors have been deleted from the registration classes.

I have code that builds up each class with repeated calls using the refl-cpp reflection framework for C++. The function signature for the function that registers the methods and properties is:

template<class T, typename TN>
void AddClassMembers(TN& bridgeClass, const char* className)
{...}

The code that creates the class does this:

   auto bridgeClass = luabridge::getGlobalNamespace(l)
                        .beginNamespace (nameSpace.c_str())
                           .beginClass<T>(name.c_str() LB3_PARM(options))
                              .template addConstructor<ConstructorArgs>();

   AddClassMembers<T>(bridgeClass, name.c_str());

   bridgeClass.endClass()
      .endNamespace();

The deleted copy constructors mean the assignment of bridgeClass fails to compile. I modified the code as follows (after examining the LB3 changes) to use && references:

template<class T, typename TN>
void AddClassMembers(TN&& bridgeClass, const char* className)
{...}
   auto&& bridgeClass = luabridge::getGlobalNamespace(l)
                        .beginNamespace (nameSpace.c_str())
                           .beginClass<T>(name.c_str() LB3_PARM(options))
                              .template addConstructor<ConstructorArgs>();

   AddClassMembers<T>(bridgeClass, name.c_str());

   bridgeClass.endClass()
      .endNamespace();

Now the code compiles, but when I run it, assertStackState fails on line 959 of Namespace.h.

kunitoki commented 1 year ago

Just stop at beginClass for the assignment.

The addXXX methods returns a reference, call them once you have a class object.


auto c = ...beginClass();
c.addConstructor();
AddMethods(c);
c.endClass();
rpatters1 commented 1 year ago

That fixed it.