mirror of
https://github.com/TangentFoxy/lua-sandbox.git
synced 2025-07-28 02:52:22 +00:00
feat(sandbox) add load mode to string functions
This commit is contained in:
committed by
Enrique García Cota
parent
ddbc7e12cc
commit
8974b8869c
@@ -138,8 +138,6 @@ end
|
||||
|
||||
-- Public interface: sandbox.protect
|
||||
function sandbox.protect(f, options)
|
||||
if type(f) == 'string' then f = assert(loadstring(f)) end
|
||||
|
||||
options = options or {}
|
||||
|
||||
local quota = false
|
||||
@@ -150,7 +148,11 @@ function sandbox.protect(f, options)
|
||||
local env = merge(options.env or {}, BASE_ENV)
|
||||
env._G = env._G or env
|
||||
|
||||
setfenv(f, env)
|
||||
if type(f) == 'string' then
|
||||
f = assert(load(f, nil, options.mode, env))
|
||||
else
|
||||
setfenv(f, env)
|
||||
end
|
||||
|
||||
return function(...)
|
||||
|
||||
|
Reference in New Issue
Block a user