title: C++ lua bridge problems with function pointers
body: <p>I am trying to create a simple c++ wraper over *lua_CFunction* and it is defined like :</p>
  
  <pre><code>// header
  typedef int (*lua_CFunction) (lua_State* lua);
  ...
  lua_CFunction wrap (std::function &lt;int (Game* game)&gt; function);
  // implementation
  lua_CFunction ScriptingInterface::wrap (std::function &lt;int (Game* game)&gt; function) 
  {
      return [this, function] (lua_State* unused) -&gt; int {
          int n_args = function (this-&gt;game);
          return n_args;
      };
  }
  void ScriptingInterface::registerFunction (std::string name, std::function &lt;int (Game* game)&gt; function) 
  {
      lua_register (lua, name.c_str (), wrap (function));
  }
  </code></pre>
  
  <p>The idea is to create public functions like this :</p>
  
  <pre><code>int setTitle (Game* interface) 
  {
      const char* title = lua_tostring (interface-&gt;getScripts ()-&gt;getLuaState (), 1);
  
      SDL_WM_SetCaption (title, NULL);
  
      return 0;
  }
  </code></pre>
  
  <p>And share them with lua like :</p>
  
  <p><code>scripts-&gt;registerFunction ("setTitle", setTitle);</code></p>
  
  <p><em>scripts</em> is an instance of <strong>ScriptingInterface</strong></p>
  
  <p>The problem occurs when trying to compile the game.</p>
  
  <pre><code>./scripting/scripting_interface.cc: In member function ‘int (* ScriptingInterface::wrap(std::function&lt;int(Game*)&gt;))(lua_State*)’:
  ./scripting/scripting_interface.cc:40:2: error: cannot convert ‘ScriptingInterface::wrap(std::function&lt;int(Game*)&gt;)::&lt;lambda(lua_State*)&gt;’ to ‘int (*)(lua_State*)’ in return
  ./scripting/scripting_interface.cc:41:1: warning: control reaches end of non-void function [-Wreturn-type]
  </code></pre>
  
  <p>Could anyone tell me what I am doing wrong in here, because AFAIK the code should compile without any problem?</p>