lua-users home
lua-l archive

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


On Fri, Mar 13, 2015 at 8:30 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> I guess you could check whether the first (or actually, any) upvalue
> has the same table as the distinguished environment. If so, you send
> some special code that says "use your distinguished environment here".
> It is true that some functions have custom environments; but, in that
> case, it seems useless to know that it is the _ENV, since you cannot
> use the receiver's _ENV there anyway.
>
> In other words, you should worry about the value, not the name. If an
> upvalue carries the distinguished environment (despite its name), you
> probably want to use the receive's distinguished environment. If an
> upvalue carries any other value (despite its name), you need some
> other solution.

This is exactly what I had to do for lua-serialize:

https://github.com/batrick/lua-serialize/blob/master/serialize.lua#L182-200

Basically, if a serialized object references a distinguished function
from the global environment, that function is not serialized and
instead loaded when the object is deserialized.

-- 
Patrick Donnelly