summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-20 21:05:11 +0800
committerruki <[email protected]>2021-09-20 21:05:11 +0800
commitbb155096b4fd14781988ef4c2488001fbe2c4938 (patch)
treec4b4884db2c7f3762eb2fe2765402908829657a2
parentc1933e6e8e7212f16443e99d66e7d656438da317 (diff)
improve interactive for lua
-rw-r--r--core/src/xmake/sandbox/interactive.c13
-rw-r--r--xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua1
2 files changed, 10 insertions, 4 deletions
diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c
index 023759448..a62f6f77c 100644
--- a/core/src/xmake/sandbox/interactive.c
+++ b/core/src/xmake/sandbox/interactive.c
@@ -73,7 +73,6 @@ static tb_void_t xm_sandbox_report(lua_State *lua)
}
}
-#ifdef USE_LUAJIT
// the traceback function
static tb_int_t xm_sandbox_traceback(lua_State *lua)
{
@@ -123,7 +122,6 @@ static tb_int_t xm_sandbox_docall(lua_State* lua, tb_int_t narg, tb_int_t clear)
// ok?
return status;
}
-#endif
// this line is incomplete?
static tb_int_t xm_sandbox_incomplete(lua_State *lua, tb_int_t status)
@@ -316,20 +314,27 @@ tb_int_t xm_sandbox_interactive(lua_State* lua)
// execute codes
if (status == 0)
{
-#ifdef USE_LUAJIT
/* bind sandbox
*
* stack: arg1(top) scriptfunc arg1(sandbox_scope) -> ...
*/
+#ifdef USE_LUAJIT
lua_pushvalue(lua, 1);
lua_setfenv(lua, -2);
+#else
+ // stack: arg1(top) scriptfunc $interactive_setfenv scriptfunc arg1(sandbox_scope) -> ...
+ lua_getfield(lua, 1, "$interactive_setfenv");
+ lua_pushvalue(lua, -2);
+ lua_pushvalue(lua, 1);
+ if (lua_pcall(lua, 2, 0, 0) != 0)
+ tb_printl(lua_pushfstring(lua, "error calling " LUA_QL("$interactive_setfenv") " (%s)", lua_tostring(lua, -1)));
+#endif
/* run script
*
* stack: arg1(top) scriptfunc -> ...
*/
status = xm_sandbox_docall(lua, 0, 0);
-#endif
}
// report errors
diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
index c8a44d266..c189f398e 100644
--- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
+++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua
@@ -93,6 +93,7 @@ function sandbox_core_sandbox.interactive()
public_scope["$interactive_dump"] = sandbox_core_sandbox._interactive_dump
public_scope["$interactive_prompt"] = colors.translate("${color.interactive.prompt}${text.interactive.prompt} ")
public_scope["$interactive_prompt2"] = colors.translate("${color.interactive.prompt2}${text.interactive.prompt2} ")
+ public_scope["$interactive_setfenv"] = setfenv
-- disable scheduler
scheduler:enable(false)