** 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. */
| 884 | ** Leaves resulting module on the top. |
| 885 | */ |
| 886 | LUALIB_API void luaL_requiref (lua_State *L, const char *modname, |
| 887 | lua_CFunction openf, int glb) { |
| 888 | lua_pushcfunction(L, openf); |
| 889 | lua_pushstring(L, modname); /* argument to open function */ |
| 890 | lua_call(L, 1, 1); /* open module */ |
| 891 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 892 | lua_pushvalue(L, -2); /* make copy of module (call result) */ |
| 893 | lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ |
| 894 | lua_pop(L, 1); /* remove _LOADED table */ |
| 895 | if (glb) { |
| 896 | lua_pushvalue(L, -1); /* copy of 'mod' */ |
| 897 | lua_setglobal(L, modname); /* _G[modname] = module */ |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | |
| 902 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
no test coverage detected