summaryrefslogtreecommitdiff
path: root/xmake/core/base/serialize.lua
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-26 14:42:05 +0800
committerOpportunityLiu <[email protected]>2019-07-28 14:45:01 +0800
commitcff42b3aeb348d0a193c24f244ddec003aded06f (patch)
tree3b5032d24b7986a80c8fbb2cc3b39ef3c62b36d8 /xmake/core/base/serialize.lua
parent4eccb9fa09f347f1b5cf64cb085a28599b2e010d (diff)
restore upvalue
Diffstat (limited to 'xmake/core/base/serialize.lua')
-rw-r--r--xmake/core/base/serialize.lua22
1 files changed, 18 insertions, 4 deletions
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua
index d6bd3885e..6e652384a 100644
--- a/xmake/core/base/serialize.lua
+++ b/xmake/core/base/serialize.lua
@@ -184,8 +184,22 @@ function serialize._resolvefunction(root, env, funccode)
if type(funccode) ~= "string" then
return nil, "func should called with a string"
end
- -- resolve
- return load(funccode, "=(deserialized code)", "b", env)
+
+ -- resolve funccode
+ local func, err = load(funccode, "=(deserialized code)", "b", env)
+ if err ~= nil then
+ return nil, err
+ end
+
+ -- try restore upvalues
+ for i = 1, math.huge do
+ local upname = debug.getupvalue(func, i)
+ if upname == nil or upname == "" then
+ break
+ end
+ debug.setupvalue(func, i, env[upname])
+ end
+ return func
end
function serialize._makeref(path, opt)
@@ -320,9 +334,9 @@ function serialize._createenv()
end
-- load function
- function env.func(funccode)
+ function env.func(...)
-- load func
- return serialize._createstub(serialize._resolvefunction, env, funccode)
+ return serialize._createstub(serialize._resolvefunction, env, ...)
end
-- return new env