[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Determining if _ENV is the first upvalue of a closure?**
**From**: Dirk Laurie <dirk.laurie@...>
**Date**: Fri, 13 Mar 2015 08:06:44 +0200

2015-03-13 7:41 GMT+02:00 Dirk Laurie <dirk.laurie@gmail.com>:
> 2015-03-13 6:43 GMT+02:00 Paul K <paul@zerobrane.com>:
>> Hi Tim,
>>
>>> The compiler clearly knows if it’s emitting a function with _ENV as the
>>> first upvalue, since it takes care to ensure it is always the first upvalue
>>> in the function. However, this information doesnt seem to make it into the
>>> compiled chunk anywhere (that I can see).
>>
>> You may try to avoid this problem by serializing a special value instead of
>> _ENV. When you serialize the upvalues, you know if the first one points to
>> the _ENV for the given function, so just store a special table value for it,
>> so that when you deserialize it to setup proper value, you know that this
>> function expects _ENV as the first upvalue, so you can do whatever is
>> appropriate in this case.
Sorry for the empty message: GMail puts the "Hidden contents" and
"Send" buttons so close together that my uncertain aim hit the wrong
one.
One can expand on Paul's idea with some simple cryptography.
do
local upvalue_marker = encrypt("This is my sign: X",private_key)
function paranoid(...)
if encrypt(upvalue_marker,public_key)~="This is my sign: X")
then return "You are not my mother!"
end
...
end
end