title: Why doesnt lua_newlib work in this example?
body: <p>I tried to call from a lua script the c method my_sin. I'm using lua 5.2.2 and wanted to test to use luaL_newlib instead of lua_register. Unfortunately, the lua script doesn't find mysin.</p>
  
  <pre><code>extern "C" {
  #include "lua.h"
  #include "lauxlib.h"
  #include "lualib.h"
  }
  
  #include &lt;cmath&gt;
  
  static int my_sin (lua_State *L) {
    lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
    return 1;
  }
  static const luaL_Reg my_lib[] = {
     {"mysin",   my_sin},
     {NULL, NULL}
  };
  
  int my_open(lua_State *L) {
    luaL_newlib(L, my_lib);  
    return 1;
  }
  
  int main() {
      lua_State* L = luaL_newstate();
      luaL_openlibs(L); 
      my_open(L);
      luaL_dostring(L, "print(mysin(2))");
      lua_close(L);
      return 0;
  }
  </code></pre>