[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Serialize closure by dump
- From: libla <libla@...>
- Date: Fri, 05 Nov 2010 09:39:39 +0800
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?