diff options
Diffstat (limited to 'xmake/core/base/serialize.lua')
| -rw-r--r-- | xmake/core/base/serialize.lua | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua index 8da0546c8..8bfc265c6 100644 --- a/xmake/core/base/serialize.lua +++ b/xmake/core/base/serialize.lua @@ -257,31 +257,33 @@ function serialize._load(str) str = "return " .. str end - local script, errors = loadstring(str) + -- load string + local script, errors = loadstring(str, "=(deserializing data)") if script then - -- load object local ok, object = pcall(script) if ok then result = object - elseif object then - -- error - errors = object else - local data - if binary then - data = "<binary data>" - elseif #str > 20 then - data = str:sub(8, 17) .. "..." - else - data = str:sub(8) - end -- error - errors = string.format("cannot deserialize string: %s", data) + errors = tostring(object) end end - return result, errors + if errors then + local data + if binary then + data = "<binary data>" + elseif #str > 30 then + data = string.format("%q... ", str:sub(8, 27)) + else + data = string.format("%q", str:sub(8)) + end + -- error + return nil, string.format("cannot deserialize %s: %s", data, errors) + end + + return result end -- deserialize string to object |
