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