lua-users home
lua-l archive

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

On 27/03/15 11:06 PM, Sean Conner wrote:
It was thus said that the Great Tim Hill once stated:
On Mar 27, 2015, at 2:28 PM, Sean Conner <> wrote:

  I would expect setting the first upvalue of meta.print() to meta would
make meta the default global environment for meta.print() and not replace
the current global environment.

Actually, the compiler makes no guarantees about which upvalue (if any)
for a function contains the _ENV environment EXCEPT in the case of the
implicit anonymous function that wraps a compiled chunk. The load() API
family always sets the first upvalue to the environment because it assumes
that the chunk being loaded was a compiled chunk (rather than an explicit
function within a chunk that was accessed with string.dump().
   But that isn't the issue.  Even if I got the wrong index, I did not expect
the global environment to change---only the environment for meta.print().


You're changing the _value_ of the upvalue and expecting the _upvalue_ to change...

Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.