| 625 | |
| 626 | |
| 627 | LUALIB_API int luaopen_package (lua_State *L) { |
| 628 | int i; |
| 629 | /* create new type _LOADLIB */ |
| 630 | luaL_newmetatable(L, "_LOADLIB"); |
| 631 | lua_pushcfunction(L, gctm); |
| 632 | lua_setfield(L, -2, "__gc"); |
| 633 | /* create `package' table */ |
| 634 | luaL_register(L, LUA_LOADLIBNAME, pk_funcs); |
| 635 | #if defined(LUA_COMPAT_LOADLIB) |
| 636 | lua_getfield(L, -1, "loadlib"); |
| 637 | lua_setfield(L, LUA_GLOBALSINDEX, "loadlib"); |
| 638 | #endif |
| 639 | lua_pushvalue(L, -1); |
| 640 | lua_replace(L, LUA_ENVIRONINDEX); |
| 641 | /* create `loaders' table */ |
| 642 | lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0); |
| 643 | /* fill it with pre-defined loaders */ |
| 644 | for (i=0; loaders[i] != NULL; i++) { |
| 645 | lua_pushcfunction(L, loaders[i]); |
| 646 | lua_rawseti(L, -2, i+1); |
| 647 | } |
| 648 | lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ |
| 649 | setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); /* set field `path' */ |
| 650 | setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ |
| 651 | /* store config information */ |
| 652 | lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" |
| 653 | LUA_EXECDIR "\n" LUA_IGMARK); |
| 654 | lua_setfield(L, -2, "config"); |
| 655 | /* set field `loaded' */ |
| 656 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 2); |
| 657 | lua_setfield(L, -2, "loaded"); |
| 658 | /* set field `preload' */ |
| 659 | lua_newtable(L); |
| 660 | lua_setfield(L, -2, "preload"); |
| 661 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 662 | luaL_register(L, NULL, ll_funcs); /* open lib into global table */ |
| 663 | lua_pop(L, 1); |
| 664 | return 1; /* return 'package' table */ |
| 665 | } |
| 666 |
nothing calls this directly
no test coverage detected