lua-users home
lua-l archive

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


> [...] (One could use debug.upvaluejoin to give it a new upvalue,
> but this is an even worse hack in my opinion.)
> 
> I would rather avoid changing the file any to accomplish this (it
> messes with debug output from errors and whatnot) -- that is, I don't
> want to add a function to each script that lets me change the
> environment dynamically. Does anyone see a better way to do this?

Basically you want to break a function abstraction, interfering from the
outside in what the function does inside. This is a hack, no matter how
you implement it. This kind of thing should not be a regular operation
in the language (as it was with setfenv).

As lhf mentioned, adding a "local _ENV = ...;" when reading your
chunk solves your problem. (It will not mess with debug output
from errors if it does not have an end of line.)

-- Roberto