Use set lookup for `sandbox_require_builtins` instead of iteration

This commit is contained in:
Gnome Ann 2021-12-30 01:45:14 -05:00
parent 3532a30ad4
commit 7645db9dd4
1 changed files with 3 additions and 5 deletions

View File

@ -1577,17 +1577,15 @@ return function(_python, _bridged)
if modname == "bridge" then
return function() return env.kobold, env.koboldcore end
end
for k, v in pairs(sandbox_require_builtins) do
if modname == k then
return env[k]
end
end
if type(modname) == "number" then
modname = tostring(modname)
elseif type(modname) ~= "string" then
error("bad argument #1 to 'require' (string expected, got "..type(modname)..")")
return
end
if sandbox_require_builtins[modname] then
return env[modname]
end
local allowsearch = type(modname) == "string" and string.match(modname, "[^%w._-]") == nil and string.match(modname, "%.%.") == nil
if allowsearch and package_loaded[env] == nil then
package_loaded[env] = {}