lua-users home
lua-l archive

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


2015-03-13 8:32 GMT+02:00 Tim Hill <drtimhill@gmail.com>:

> Yes, I know how to represent _ENV in the serialization as a placeholder.
> The problem is the code DOESN’T actually know if the closure has _ENV
> or not in the first upvalue. Hard-wiring in this knowledge into the code is
> very fragile, as even a minor one-line change to a function can change the
> status of the first upvalue. I’d much prefer a way to determine by inspection
> if _ENV is in the first upvalue or not.

Is this a correct summary of the problem you need to solve?

1. LuaState 1, to which you have full access, dumps a function,
    the source of which you write, to a string.
2. LuaState 2,  to which you do not have full access, somehow
   gets that string, loads it and calls it.
3. You wish to write your code in such a way that the running
   function can detect whether it has been called with first upvalue
   equal to the table in which it looks up global variables.