MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaL_requiref

Function luaL_requiref

third-party/lua-5.3.5/src/lauxlib.c:971–988  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

969** Leaves resulting module on the top.
970*/
971LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
972 lua_CFunction openf, int glb) {
973 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
974 lua_getfield(L, -1, modname); /* LOADED[modname] */
975 if (!lua_toboolean(L, -1)) { /* package not already loaded? */
976 lua_pop(L, 1); /* remove field */
977 lua_pushcfunction(L, openf);
978 lua_pushstring(L, modname); /* argument to open function */
979 lua_call(L, 1, 1); /* call 'openf' to open module */
980 lua_pushvalue(L, -1); /* make copy of module (call result) */
981 lua_setfield(L, -3, modname); /* LOADED[modname] = module */
982 }
983 lua_remove(L, -2); /* remove LOADED table */
984 if (glb) {
985 lua_pushvalue(L, -1); /* copy of module */
986 lua_setglobal(L, modname); /* _G[modname] = module */
987 }
988}
989
990
991LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,

Callers 1

luaL_openlibsFunction · 0.70

Calls 9

luaL_getsubtableFunction · 0.70
lua_getfieldFunction · 0.70
lua_tobooleanFunction · 0.70
lua_pushstringFunction · 0.70
lua_pushvalueFunction · 0.70
lua_setfieldFunction · 0.70
lua_setglobalFunction · 0.70
lua_callFunction · 0.50
lua_removeFunction · 0.50

Tested by

no test coverage detected