[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Serialize closure by dump
- From: Michal Kolodziejczyk <miko@...>
- Date: Fri, 05 Nov 2010 08:57:03 +0100
On 05.11.2010 02:39, libla wrote:
> I try to serialized closure used "string.dump", but I find that the
> upvalues were set nil when deserialize the closure.
[...]
> Output: nil nil nil
>
> Is there any solution?
You are serializing the function alone, and expect that the function is
serialized with its environment (ie, the current state of the
interpreter), which is not true.
You could rewrite your serializing/deserializing functions to include
the environment of a function. Check out debug.getfenv() and
debug.getupvalue(), and maybe also debug.getlocal() and
debug.getmetatable().
Regards,
miko