lua-users home
lua-l archive

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


On Tue, Jan 12, 2010 at 01:25:36PM -0200, Roberto Ierusalimschy wrote:
> We are not sure whether everything that was doable is still doable, but
> the main point is that we were not sure whether everything that was
> doable should be doable.

I am interested as to whether my primary use of setfenv is considered "should
be doable" and whether it is under 5.2.  I'll admit I've not had the time to
investigate yet, so please feel free to point me at something and tell me to
go-forth-and-read.

I use function environments to create sub-languages which I use for internal
scripting and to isolate "client" code when running sandboxed scripts etc.  For
example; in a package manager I am writing currently, I am using function
environments to deliberately isolate package activation (post-install) scripts
from one-another and from the power of the enclosing interpreter.

To do this, I create an environment consisting of just the functions I want
exposed; then loadfile() the script, set the environment and then run the
function.  The functions in the environment are carefully crafted so as to only
use lexically scoped variables to handle their needs and to be as simple as
possible, as the entire function is run with a hook set to prevent it from
running indefinitely.

How would I do this under Lua 5.2?  If the answer is to load the snippets as
strings and prefix/suffix them; then the answer is deeply inconvenient since it
means that compilation errors would be offset by that additional cruft and thus
not necessarily relate to the file which a user would have to debug.

Regards,

Daniel.

P.S. I also make use of environements with metatables; so it's not just limited
to simple key/value replacements.

-- 
Daniel Silverstone                         http://www.digital-scurf.org/
PGP mail accepted and encouraged.            Key Id: 3CCE BABE 206C 3B69