New interface to function 'luaL_openselectedlibs'

Instead of preloading all non-loaded libraries, there is another
mask to select which libraries to preload.
This commit is contained in:
Roberto Ierusalimschy
2024-02-15 11:17:39 -03:00
parent c8121ce34b
commit 165389b27b
8 changed files with 80 additions and 56 deletions

View File

@@ -1223,8 +1223,9 @@ static lua_State *getstate (lua_State *L) {
static int loadlib (lua_State *L) {
lua_State *L1 = getstate(L);
int what = luaL_checkinteger(L, 2);
luaL_openselectedlibs(L1, what);
int load = luaL_checkinteger(L, 2);
int preload = luaL_checkinteger(L, 3);
luaL_openselectedlibs(L1, load, preload);
luaL_requiref(L1, "T", luaB_opentests, 0);
lua_assert(lua_type(L1, -1) == LUA_TTABLE);
/* 'requiref' should not reload module already loaded... */