vinniefalco/LuaBridge

Using a templated function as a method proxy.

rpatters1 opened this issue · 2 comments

Here is skeleton code for a method proxy:

template<class C, const char* NAME>
static const char* className(const C*)
{
   return NAME;
}
class foo {};
static const char* fooName(const foo*)
{
   return "foo";
}

void myfunc(lua_State* L)
{
   luabridge::getGlobalNamespace(L)
      .beginNamespace("foobar")
         .beginClass<foo>("foo")
            .addFunction("ClassName", &className<foo, "foo">)  // <<--- Fails with "no matching member function call to 'addFunction'"
            .addFunction("ClassName", &fooName) // <<--- works
         .endClass()
      .endNamespace();
}

I am having trouble understanding why the fully-qualified template function gets a compiler error.

Your templated function has a non type template argument which makes it an overloaded function and can't be resolved. https://godbolt.org/z/7fz6PEhj7

Okay, thanks for the tip. Am closing this issue.