lua-users home
lua-l archive

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


It was thus said that the Great Dong Feng once stated:
> 2015-03-27 21:16 GMT-07:00 Sean Conner <sean@conman.org>:
> 
> >   Also, while "you can use the debug library to serialize and reload the
> > upvalues of a function in a way adequate to your needs" is true, to a
> > degree, as mentioned elsewhere [2] it's not always that easy.
> >
> >   -spc (Why yes, I'm trying to serialize Lua functions, silly me)
> >
> > [2]     http://lua-users.org/lists/lua-l/2015-03/msg00180.html
>
> I have three points regarding this:
> 
> First, this isn't 5.3 specific. You'd get the same in 5.2.
> 
> Second, the document load() says it sets the "first" upval. Well, that's
> correct from the perspective of implementation. However, its intention is
> really to set the ONLY upval. 

  Not quite.  string.dump() states:  "Functions with upvalues have only their
number of upvalues saved."  And I'm loading the output from string.dump()
via load().  So Lua knows how many upvalues it has, but not which one was
_ENV.

> The implied recommendation is, don't play
> load() with anything but main chunk (which does not have upval except _ENV).

  I'm not sure what you mean by this.

 > Third, well, the document says you can serialize Lua function by
> string.dump and deserialize it by load. That's fine. Only in this case, you
> deserialize what you serialize, and you should not make any assumption what
> the "first" would be.

  Yeah, and all upvalues are set to nil, except the first.  And if you try
to run that function before the upvalues are fixed, well ... 

  -spc