diff options
| author | OpportunityLiu <[email protected]> | 2019-07-26 16:25:52 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-28 14:45:01 +0800 |
| commit | d3667d71c86861ffb910af8ba8ecd930f75bf9e7 (patch) | |
| tree | 5a0014b413aae30fc60d2d084aac98c9575eddf7 /xmake/core/base/serialize.lua | |
| parent | cff42b3aeb348d0a193c24f244ddec003aded06f (diff) | |
fix up value
Diffstat (limited to 'xmake/core/base/serialize.lua')
| -rw-r--r-- | xmake/core/base/serialize.lua | 20 |
1 files changed, 11 insertions, 9 deletions
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 |
