From d738c8d18bcc5651109b3a46103d6aa983772e68 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 7 Dec 2022 15:12:52 -0300 Subject: New function 'luaL_openselectedlibs' Makes it easier to start Lua with only some standard libraries. --- testes/api.lua | 14 ++++++++------ testes/coroutine.lua | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'testes') diff --git a/testes/api.lua b/testes/api.lua index bd85a923..f8e36ae3 100644 --- a/testes/api.lua +++ b/testes/api.lua @@ -1039,10 +1039,12 @@ assert(a == nil and b == 2) -- 2 == run-time error a, b, c = T.doremote(L1, "return a+") assert(a == nil and c == 3 and type(b) == "string") -- 3 == syntax error -T.loadlib(L1) +T.loadlib(L1, 2) -- load only 'package' a, b, c = T.doremote(L1, [[ string = require'string' - a = require'_G'; assert(a == _G and require("_G") == a) + local initialG = _G -- not loaded yet + local a = require'_G'; assert(a == _G and require("_G") == a) + assert(initialG == nil and io == nil) -- now we have 'assert' io = require'io'; assert(type(io.read) == "function") assert(require("io") == io) a = require'table'; assert(type(a.insert) == "function") @@ -1056,7 +1058,7 @@ T.closestate(L1); L1 = T.newstate() -T.loadlib(L1) +T.loadlib(L1, 0) T.doremote(L1, "a = {}") T.testC(L1, [[getglobal "a"; pushstring "x"; pushint 1; settable -3]]) @@ -1436,10 +1438,10 @@ end do -- garbage collection with no extra memory local L = T.newstate() - T.loadlib(L) + T.loadlib(L, 1 | 2) -- load _G and 'package' local res = (T.doremote(L, [[ - _ENV = require"_G" - local T = require"T" + _ENV = _G + assert(string == nil) local a = {} for i = 1, 1000 do a[i] = 'i' .. i end -- grow string table local stsize, stuse = T.querystr() diff --git a/testes/coroutine.lua b/testes/coroutine.lua index 15fccc30..f05672a5 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua @@ -694,7 +694,7 @@ else T.testC(state, "settop 0") - T.loadlib(state) + T.loadlib(state, 1 | 2) -- load _G and 'package' assert(T.doremote(state, [[ coroutine = require'coroutine'; -- cgit v1.2.3-55-g6feb