mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-02-17 12:10:49 +01:00
Allow require()
in userscripts to import built-in modules
This commit is contained in:
parent
38bad263e1
commit
35539a8785
17
bridge.lua
17
bridge.lua
@ -1511,6 +1511,18 @@ return function(_python, _bridged)
|
||||
koboldbridge.logging_name = nil
|
||||
koboldbridge.filename = nil
|
||||
|
||||
local sandbox_require_builtins = {
|
||||
coroutine = true,
|
||||
package = true,
|
||||
string = true,
|
||||
utf8 = true,
|
||||
table = true,
|
||||
math = true,
|
||||
io = true,
|
||||
os = true,
|
||||
debug = true,
|
||||
}
|
||||
|
||||
local old_load = load
|
||||
local function _safe_load(_g)
|
||||
return function(chunk, chunkname, mode, env)
|
||||
@ -1541,6 +1553,11 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user