mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Allow require()
in userscripts to import built-in modules
This commit is contained in:
17
bridge.lua
17
bridge.lua
@@ -1511,6 +1511,18 @@ return function(_python, _bridged)
|
|||||||
koboldbridge.logging_name = nil
|
koboldbridge.logging_name = nil
|
||||||
koboldbridge.filename = 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 old_load = load
|
||||||
local function _safe_load(_g)
|
local function _safe_load(_g)
|
||||||
return function(chunk, chunkname, mode, env)
|
return function(chunk, chunkname, mode, env)
|
||||||
@@ -1541,6 +1553,11 @@ return function(_python, _bridged)
|
|||||||
if modname == "bridge" then
|
if modname == "bridge" then
|
||||||
return function() return env.kobold, env.koboldcore end
|
return function() return env.kobold, env.koboldcore end
|
||||||
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
|
if type(modname) == "number" then
|
||||||
modname = tostring(modname)
|
modname = tostring(modname)
|
||||||
elseif type(modname) ~= "string" then
|
elseif type(modname) ~= "string" then
|
||||||
|
Reference in New Issue
Block a user