** Stripped-down 'require': After checking "loaded" table, 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. */
| 2971 | ** Leaves resulting module on the top. |
| 2972 | */ |
| 2973 | LUALIB_API void luaL_requiref(lua_State *L, const char *modname, |
| 2974 | lua_CFunction openf, int glb) { |
| 2975 | luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 2976 | lua_getfield(L, -1, modname); /* _LOADED[modname] */ |
| 2977 | if (!lua_toboolean(L, -1)) { /* package not already loaded? */ |
| 2978 | lua_pop(L, 1); /* remove field */ |
| 2979 | lua_pushcfunction(L, openf); |
| 2980 | lua_pushstring(L, modname); /* argument to open function */ |
| 2981 | lua_call(L, 1, 1); /* call 'openf' to open module */ |
| 2982 | lua_pushvalue(L, -1); /* make copy of module (call result) */ |
| 2983 | lua_setfield(L, -3, modname); /* _LOADED[modname] = module */ |
| 2984 | } |
| 2985 | lua_remove(L, -2); /* remove _LOADED table */ |
| 2986 | if (glb) { |
| 2987 | lua_pushvalue(L, -1); /* copy of module */ |
| 2988 | lua_setglobal(L, modname); /* _G[modname] = module */ |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | |
| 2993 | LUALIB_API const char *luaL_gsub(lua_State *L, const char *s, const char *p, |
no test coverage detected