| 591 | }; |
| 592 | |
| 593 | LUALIB_API int luaopen_package(lua_State *L) |
| 594 | { |
| 595 | int i; |
| 596 | int noenv; |
| 597 | luaL_newmetatable(L, "_LOADLIB"); |
| 598 | lj_lib_pushcf(L, lj_cf_package_unloadlib, 1); |
| 599 | lua_setfield(L, -2, "__gc"); |
| 600 | luaL_register(L, LUA_LOADLIBNAME, package_lib); |
| 601 | lua_copy(L, -1, LUA_ENVIRONINDEX); |
| 602 | lua_createtable(L, sizeof(package_loaders)/sizeof(package_loaders[0])-1, 0); |
| 603 | for (i = 0; package_loaders[i] != NULL; i++) { |
| 604 | lj_lib_pushcf(L, package_loaders[i], 1); |
| 605 | lua_rawseti(L, -2, i+1); |
| 606 | } |
| 607 | #if LJ_52 |
| 608 | lua_pushvalue(L, -1); |
| 609 | lua_setfield(L, -3, "searchers"); |
| 610 | #endif |
| 611 | lua_setfield(L, -2, "loaders"); |
| 612 | lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); |
| 613 | noenv = lua_toboolean(L, -1); |
| 614 | lua_pop(L, 1); |
| 615 | setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv); |
| 616 | setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv); |
| 617 | lua_pushliteral(L, LUA_PATH_CONFIG); |
| 618 | lua_setfield(L, -2, "config"); |
| 619 | luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); |
| 620 | lua_setfield(L, -2, "loaded"); |
| 621 | luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 4); |
| 622 | lua_setfield(L, -2, "preload"); |
| 623 | lua_pushvalue(L, LUA_GLOBALSINDEX); |
| 624 | luaL_register(L, NULL, package_global); |
| 625 | lua_pop(L, 1); |
| 626 | return 1; |
| 627 | } |
| 628 |
nothing calls this directly
no test coverage detected