Re: Serialize closure by dump
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Serialize closure by dump
- From: GrayFace <sergroj@...>
- Date: 2010年11月05日 09:29:17 +0600
Yes, there's no way for dump to serialize upvalues, because they may be
shared among functions. Use upvalueid and upvaluejoin from Lua 5.2 to
serialize and deserialize upvalues. Here they are for Lua 5.1:
https://sites.google.com/site/sergroj/news/upvaluejoin.rar?attredirects=0&d=1
I can also send you my serialization code. I haven't released it to the
public yet.
On 05.11.2010 7:39, libla wrote:
> 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?
>
>
>
>
--
Best regards,
Sergey Rozhenko mailto:sergroj@mail.ru