MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaopen_package

Function luaopen_package

Source/Misc/lua/src/lua.c:13395–13433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13393
13394
13395LUALIB_API int luaopen_package (lua_State *L) {
13396int i;
13397/* create new type _LOADLIB */
13398luaL_newmetatable(L, "_LOADLIB");
13399lua_pushcfunction(L, gctm);
13400lua_setfield(L, -2, "__gc");
13401/* create `package' table */
13402luaL_register(L, LUA_LOADLIBNAME, pk_funcs);
13403#if defined(LUA_COMPAT_LOADLIB)
13404lua_getfield(L, -1, "loadlib");
13405lua_setfield(L, LUA_GLOBALSINDEX, "loadlib");
13406#endif
13407lua_pushvalue(L, -1);
13408lua_replace(L, LUA_ENVIRONINDEX);
13409/* create `loaders' table */
13410lua_createtable(L, 0, sizeof(loaders)/sizeof(loaders[0]) - 1);
13411/* fill it with pre-defined loaders */
13412for (i=0; loaders[i] != NULL; i++) {
13413lua_pushcfunction(L, loaders[i]);
13414lua_rawseti(L, -2, i+1);
13415}
13416lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */
13417setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */
13418setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */
13419/* store config information */
13420lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n"
13421LUA_EXECDIR "\n" LUA_IGMARK);
13422lua_setfield(L, -2, "config");
13423/* set field `loaded' */
13424luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2);
13425lua_setfield(L, -2, "loaded");
13426/* set field `preload' */
13427lua_newtable(L);
13428lua_setfield(L, -2, "preload");
13429lua_pushvalue(L, LUA_GLOBALSINDEX);
13430luaL_register(L, NULL, ll_funcs); /* open lib into global table */
13431lua_pop(L, 1);
13432return 1; /* return 'package' table */
13433}
13434
13435/*
13436** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected