title: How to get lua function as parameter in C++ and then call it
body: <p>I'm implementing lua api (5.1) in C++ and got problem, couldn't pass lua function as paramater in c++ function called from lua. Example (Main function is called from C++):</p>
  
  <p>Lua:</p>
  
  <pre><code>function Main()
      HookEntityFunction("player", 1, PlayerSpawn); -- &lt;&lt; is this normal?
  end
  
  function PlayerSpawn()
  
  end
  </code></pre>
  
  <p>C++:</p>
  
  <pre><code>int HookEntityFunction(lua_State *L)
  {
      lua_CFunction F = lua_tocfunction(L, 3); -- &lt;&lt; how to call it?
  }
  </code></pre>