diff options
| -rw-r--r-- | core/src/xmake/sandbox/interactive.c | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua | 17 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 13 |
3 files changed, 22 insertions, 10 deletions
diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 8a3db4ca1..ac2653021 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -204,7 +204,7 @@ static tb_int_t loadline(lua_State *lua) // add a new line lua_pushliteral(lua, "\n"); - // cannot try to add lines? + // cannot try to add lines? lua_insert(lua, -2); // join them diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index ba0481726..da24536ba 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -31,6 +31,23 @@ local raise = require("sandbox/modules/raise") -- enter interactive mode function sandbox_core_sandbox.interactive() + + -- get the current sandbox instance + local instance = sandbox.instance() + if not instance then + raise("cannot get sandbox instance!") + end + + -- fork a new sandbox + instance, errors = instance:fork() + if not instance then + raise(errors) + end + + -- bind sandbox environment + setfenv(0, instance._PUBLIC) + + -- enter interactive mode with this new sandbox sandbox.interactive() end diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index fe5648cbd..1ca11e4fd 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -195,11 +195,6 @@ end -- fork a new sandbox from the given sandbox function sandbox:fork(script, rootdir) - -- no script? - if script == nil then - return nil, "no script!" - end - -- invalid script? if script ~= nil and type(script) ~= "function" then return nil, "invalid script!" @@ -218,10 +213,10 @@ function sandbox:fork(script, rootdir) instance._PRIVATE._ROOTDIR = rootdir or self:rootdir() -- bind public scope - setfenv(script, instance._PUBLIC) - - -- save script - instance._PRIVATE._SCRIPT = script + if script then + setfenv(script, instance._PUBLIC) + instance._PRIVATE._SCRIPT = script + end -- ok? return instance |
