/* stripped-down 'require'. Calls 'openf' to open a module, registers the result in 'package.loaded' table and, if 'glb' is true, also registers the result in the global table. Leaves resulting module on the top.  */
LUALIB_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
/* stripped-down 'require'. Calls 'openf' to open a module, registers the result in 'package.loaded' table and, if 'glb' is true, also registers the result in the global table. Leaves resulting module on the top.  */
LUALIB_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
{
  lua_pushcfunction(L, openf);
  lua_pushstring(L, modname);
  lua_call(L, 1, 1);
  luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
  lua_pushvalue(L, -2);
  lua_setfield(L, -2, modname);
  lua_pop(L, 1);
  if (glb) {
    lua_pushvalue(L, -1);
    lua_setglobal(L, modname);
  }
}