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

Function luaopen_package

third-party/lua-5.2.4/src/loadlib.c:690–724  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

688
689
690LUAMOD_API int luaopen_package (lua_State *L) {
691 /* create table CLIBS to keep track of loaded C libraries */
692 luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
693 lua_createtable(L, 0, 1); /* metatable for CLIBS */
694 lua_pushcfunction(L, gctm);
695 lua_setfield(L, -2, "__gc"); /* set finalizer for CLIBS table */
696 lua_setmetatable(L, -2);
697 /* create `package' table */
698 luaL_newlib(L, pk_funcs);
699 createsearcherstable(L);
700#if defined(LUA_COMPAT_LOADERS)
701 lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
702 lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */
703#endif
704 lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
705 /* set field 'path' */
706 setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT);
707 /* set field 'cpath' */
708 setpath(L, "cpath", LUA_CPATHVERSION, LUA_CPATH, LUA_CPATH_DEFAULT);
709 /* store config information */
710 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n"
711 LUA_EXEC_DIR "\n" LUA_IGMARK "\n");
712 lua_setfield(L, -2, "config");
713 /* set field `loaded' */
714 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
715 lua_setfield(L, -2, "loaded");
716 /* set field `preload' */
717 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
718 lua_setfield(L, -2, "preload");
719 lua_pushglobaltable(L);
720 lua_pushvalue(L, -2); /* set 'package' as upvalue for next lib */
721 luaL_setfuncs(L, ll_funcs, 1); /* open lib into global table */
722 lua_pop(L, 1); /* pop global table */
723 return 1; /* return 'package' table */
724}
725

Callers

nothing calls this directly

Calls 9

luaL_getsubtableFunction · 0.70
lua_createtableFunction · 0.70
lua_setfieldFunction · 0.70
lua_setmetatableFunction · 0.70
createsearcherstableFunction · 0.70
lua_pushvalueFunction · 0.70
setpathFunction · 0.70
luaL_setfuncsFunction · 0.70
lua_pushglobaltableFunction · 0.50

Tested by

no test coverage detected