summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-05-02 16:26:44 +0800
committerruki <[email protected]>2017-05-02 16:26:44 +0800
commit8599e843cc0ed678c0694686975467d73edc93fe (patch)
tree3dd971f545cfd1e8807e0d8ccea8710cb372cc2b
parente269996c0e8e09596622b378874d06e931f1f109 (diff)
bind ineractive sandbox
-rw-r--r--core/src/xmake/sandbox/interactive.c2
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua17
-rw-r--r--xmake/core/sandbox/sandbox.lua13
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