summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-04-19 00:42:27 +0800
committerruki <[email protected]>2025-08-28 11:35:53 +0800
commit9de0be5040e3feda8aface1174cd1e6fc696fe4e (patch)
treeb9256e58a7acfe57d8d6252277f8247b74bfa56d
parent5c371c00ead44993b83f26a754c32a3f8a799aa4 (diff)
bind sandbox
-rw-r--r--tests/modules/thread/sleep.lua3
-rw-r--r--xmake/core/base/serialize.lua8
-rw-r--r--xmake/core/base/task.lua21
-rw-r--r--xmake/core/main.lua19
4 files changed, 28 insertions, 23 deletions
diff --git a/tests/modules/thread/sleep.lua b/tests/modules/thread/sleep.lua
index 9f7bb859c..cfc314c4c 100644
--- a/tests/modules/thread/sleep.lua
+++ b/tests/modules/thread/sleep.lua
@@ -1,8 +1,9 @@
import("core.thread.thread")
function callback(id)
- print("hello")
+ print(import)
--[[
+ import("core.thread.thread")
print("%s: %d starting ..", thread.running(), id)
local dt = os.mclock()
for i = 1, 10 do
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua
index b45d5587f..665fe04a6 100644
--- a/xmake/core/base/serialize.lua
+++ b/xmake/core/base/serialize.lua
@@ -167,7 +167,6 @@ function serialize._makefunction(func, opt)
end
function serialize._resolvefunction(root, fenv, bytecode)
- -- check
if type(bytecode) ~= "string" then
return nil, string.format("invalid bytecode (string expected, got %s)", type(bytecode))
end
@@ -191,7 +190,10 @@ function serialize._resolvefunction(root, fenv, bytecode)
if upname == nil or upname == "" then
break
end
- debug.setupvalue(func, i, fenv[upname])
+ local upvalue = fenv[upname]
+ if upvalue ~= nil then
+ debug.setupvalue(func, i, upvalue)
+ end
end
end
return func
@@ -477,8 +479,6 @@ end
-- @return obj, errors
--
function serialize.load(str)
-
- -- check
assert(str)
-- load string
diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua
index df865b92d..29cca38f2 100644
--- a/xmake/core/base/task.lua
+++ b/xmake/core/base/task.lua
@@ -344,28 +344,21 @@ function task._load(filepath)
if not ok then
return nil, errors
end
-
- -- ok?
return tasks
end
-- get task apis
function task.apis()
-
- return
- {
- values =
- {
+ return {
+ values = {
-- task.set_xxx
"task.set_category" -- main, action, plugin, task (default)
- }
- , dictionary =
- {
+ },
+ dictionary = {
-- task.set_xxx
"task.set_menu"
- }
- , script =
- {
+ },
+ script = {
-- task.on_xxx
"task.on_run"
}
@@ -490,8 +483,6 @@ end
-- run given task
function task:run(...)
-
- -- check
local on_run = self:get("run")
if not on_run then
return false, string.format("task(\"%s\"): no run script, please call on_run() first!", self:fullname())
diff --git a/xmake/core/main.lua b/xmake/core/main.lua
index 632165717..826a2c3d8 100644
--- a/xmake/core/main.lua
+++ b/xmake/core/main.lua
@@ -41,6 +41,7 @@ local project = require("project/project")
local localcache = require("cache/localcache")
local profiler = require("base/profiler")
local debugger = require("base/debugger")
+local sandbox = require("sandbox/sandbox")
-- init the option menu
local menu =
@@ -276,15 +277,27 @@ end
-- run thread
function main._run_thread(callinfo_str)
+
+ -- get callback info
local callinfo, errors = string.deserialize(callinfo_str)
if not callinfo then
return false, string.format("invalid thread callinfo, %s!", errors or "unknown")
end
local callback = callinfo.callback
- if callback then
- callback(callinfo.argv)
+ if not callback then
+ return false, string.format("no callback")
end
- return true
+
+ -- bind sandbox
+-- local sandbox_inst, errors = sandbox.new(callback, {
+-- filter = interp:filter(), rootdir = interp:rootdir(), namespace = interp:namespace()})
+ local sandbox_inst, errors = sandbox.new(callback)
+ if not sandbox_inst then
+ return false, errors
+ end
+
+ -- do callback
+ return sandbox.load(sandbox_inst:script(), table.unpack(callinfo.argv or {}))
end
-- the main entry function