From d3667d71c86861ffb910af8ba8ecd930f75bf9e7 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Fri, 26 Jul 2019 16:25:52 +0800 Subject: fix up value --- xmake/core/base/serialize.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'xmake/core/base/serialize.lua') diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua index 6e652384a..f5e078da0 100644 --- a/xmake/core/base/serialize.lua +++ b/xmake/core/base/serialize.lua @@ -50,7 +50,7 @@ function serialize._resolvestub(object, root, fenv) end for k, v in pairs(object) do - local result, errors = serialize._resolvestub(v, root, env) + local result, errors = serialize._resolvestub(v, root, fenv) if errors ~= nil then return nil, errors end @@ -179,25 +179,27 @@ function serialize._makefunction(func, opt) return string.format("func%q", funccode) end -function serialize._resolvefunction(root, env, funccode) +function serialize._resolvefunction(root, fenv, funccode) -- check if type(funccode) ~= "string" then return nil, "func should called with a string" end -- resolve funccode - local func, err = load(funccode, "=(deserialized code)", "b", env) + local func, err = load(funccode, "=(deserialized code)", "b", fenv) 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 + if fenv then + for i = 1, math.huge do + local upname = debug.getupvalue(func, i) + if upname == nil or upname == "" then + break + end + debug.setupvalue(func, i, fenv[upname]) end - debug.setupvalue(func, i, env[upname]) end return func end @@ -217,7 +219,7 @@ function serialize._makeref(path, opt) return "ref(" .. table.concat(ppath, opt.indent and ", " or ",") .. ")" end -function serialize._resolveref(root, env, ...) +function serialize._resolveref(root, fenv, ...) local pos = root for i, v in ipairs({...}) do if type(v) ~= "string" and type(v) ~= "number" then -- cgit v1.3.1