lua-users home
lua-l archive

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

> On Mar 13, 2015, at 1:12 AM, Dirk Laurie <> wrote:
> 2015-03-13 8:32 GMT+02:00 Tim Hill <>:
>> 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.

Yes on 1 and 2, if “full access” means I control the underlying C code that runs the state. I do NOT have full control of the corpus of Lua code running on the state.

For #3, it’s not the *running* function that I’m serializing, it’s an arbitrary function (well, closure), passed as an argument to a “transfer()” API that does the serialization.