static void thread_openlibs (lua_State *L, unsigned int loadlibs) { const char *const *libnamep; int i; thread_openlib(L, "_G", luaopen_base); thread_openlib(L, LUA_LOADLIBNAME, luaopen_package); #if LUA_VERSION_NUM < 502 lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); #else luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD"); #endif for (i = 0, libnamep = stdlib_names; *libnamep; ++i, ++libnamep) { const char *name = *libnamep; lua_CFunction func = stdlib_funcs[i]; if ((loadlibs & (1 << i))) thread_openlib(L, name, func); else thread_setfield(L, name, func); } lua_pop(L, 1); /* remove package.preload table */ }
static void thread_openlibs (lua_State *L) { thread_openlib(L, "", luaopen_base); thread_openlib(L, LUA_LOADLIBNAME, luaopen_package); lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); thread_setfield(L, LUA_TABLIBNAME, luaopen_table); thread_setfield(L, LUA_IOLIBNAME, luaopen_io); thread_setfield(L, LUA_OSLIBNAME, luaopen_os); thread_setfield(L, LUA_STRLIBNAME, luaopen_string); thread_setfield(L, LUA_MATHLIBNAME, luaopen_math); thread_setfield(L, LUA_DBLIBNAME, luaopen_debug); lua_pop(L, 2); luaopen_sys_thread(L); /* create table of threads */ }