lua-users home
lua-l archive

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


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