lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


 I try to serialized closure used "string.dump", but I find that the
upvalues were set nil when deserialize the closure.

Code of serialization:
function creator()
local a = 1
local b = 2
local c = 3
return function() print(a,b,c) end
end
f = creator()
f()
file = io.open("input", "wb")
file:write(string.dump(f))
file:close()

Output: 1 2 3

Code of deserialization:
file = io.open("input", "rb")
f = loadstring(file:read("*all"))
file:close()
f()

Output: nil nil nil

Is there any solution?