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