MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / luaopen_package

Function luaopen_package

other_src/lua/src/loadlib.cpp:642–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

640
641
642LUALIB_API int luaopen_package (lua_State *L) {
643 int i;
644 /* create new type _LOADLIB */
645 luaL_newmetatable(L, "_LOADLIB");
646 lua_pushcfunction(L, gctm);
647 lua_setfield(L, -2, "__gc");
648 /* create `package' table */
649 luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
650#if defined(LUA_COMPAT_LOADLIB)
651 lua_getfield(L, -1, "loadlib");
652 lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
653#endif
654 lua_pushvalue(L, -1);
655 lua_replace(L, LUA_ENVIRONINDEX);
656 /* create `loaders' table */
657 lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0);
658 /* fill it with pre-defined loaders */
659 for (i=0; loaders[i] != NULL; i++) {
660 lua_pushcfunction(L, loaders[i]);
661 lua_rawseti(L, -2, i+1);
662 }
663 lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */
664 setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */
665 setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
666 /* store config information */
667 lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
668 LUA_EXECDIR "\n" LUA_IGMARK);
669 lua_setfield(L, -2, "config");
670 /* set field `loaded' */
671 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
672 lua_setfield(L, -2, "loaded");
673 /* set field `preload' */
674 lua_newtable(L);
675 lua_setfield(L, -2, "preload");
676 lua_pushvalue(L, LUA_GLOBALSINDEX);
677 luaL_register(L, NULL, ll_funcs); /* open lib into global table */
678 lua_pop(L, 1);
679 return 1; /* return 'package' table */
680}
681

Callers

nothing calls this directly

Calls 9

luaL_newmetatableFunction · 0.70
lua_setfieldFunction · 0.70
lua_getfieldFunction · 0.70
lua_pushvalueFunction · 0.70
lua_replaceFunction · 0.70
lua_createtableFunction · 0.70
lua_rawsetiFunction · 0.70
setpathFunction · 0.70
luaL_findtableFunction · 0.70

Tested by

no test coverage detected