title: C++ class member function pointer to function pointer
body: <p>I am using luabind as my lua to C++ wrapper. Luabind offers a method to use my own callback function to handle exceptions thrown by lua, set_pcall_callback(). So I paraphrased an example from the documentation, the changes being the logger->log() function and putting the function in a class called 'Engine', so instead of it being a regular global function it is now a member function, which is where my problem seems to be.</p>
  
  <p>Here are the relevant code snips:</p>
  
  <pre><code>class Engine //Whole class not shown for brevity
  {
  public:
      Engine();
      ~Engine();
      void Run();
      int pcall_log(lua_State*);
  private:
      ILogger *logger;
  };
  
  Engine::Run()
  {
  lua_State* L = lua_open();
  luaL_openlibs(L);
  open(L);
  luabind::set_pcall_callback(&amp;Engine::pcall_log); //&lt;--- Problem line
  //etc...rest of the code not shown for brevity
  }
  
  int Engine::pcall_log(lua_State *L)
  {
  lua_Debug d;
  lua_getstack( L,1,&amp;d);
  lua_getinfo( L, "Sln", &amp;d);
  lua_pop(L, 1);
  stringstream ss;
  ss.clear();
  ss.str("");
  ss &lt;&lt; d.short_src;
  ss &lt;&lt; ": ";
  ss &lt;&lt; d.currentline;
  ss &lt;&lt; ": ";
  if ( d.name != 0)
  {
      ss &lt;&lt; d.namewhat;
      ss &lt;&lt; " ";
      ss &lt;&lt; d.name;
      ss &lt;&lt; ") ";
  }
  ss &lt;&lt; lua_tostring(L, -1);
  logger-&gt;log(ss.str().c_str(),ELL_ERROR);
  return 1;
  }
  </code></pre>
  
  <p>Here is what the compiler says during compilation:</p>
  
  <pre><code>C:\pb\engine.cpp|31|error: cannot convert 'int (Engine::*)(lua_State*)' to 'int (*)(lua_State*)' for argument '1' to 'void luabind::set_pcall_callback(int (*)(lua_State*))'|
  </code></pre>
  
  <p>So it seems that the error is that the function expects a regular function pointer, not a class member function pointer. Is there a way to cast or use an intermediate function pointer to pass to the set_pcall_callback() function?</p>
  
  <p>Thank you!</p>