lua-users home
lua-l archive

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


> If Lua is going to shy away from introducing an explicit finalization  
> mechanism, how about introducing better mechanisms for manipulating  
> function environments (which would better support John's scope system in 
> Lua Gems)?
>
> Vaguely:
>
> 1. There needs to be a way to replace the environment on a function and 
> get a new function. This would be useful in a variety of contexts. But 
> examples like John's which save and restore the environment seem fraught 
> with danger. (I've also wanted this capability when designing object 
> systems and thinking about how to define "super").
>
> 2. It would be nice to have a way to call a function with a particular  
> environment even if that function has a protected environment. Something 
> like:
>
> 	call_with_environment( environment, nesting, fn, ... )
>
> This does not change the actual environment on fn. It merely changes the 
> environment used in the call. If nesting is true, then we want to  
> construct an environment that uses the supplied environment and then  
> chains to the actual environment. (Definition of chaining TBD.)

If you have (1) than you get (2), no? (Create the clone and call it.)

But (1) seems dangerous in some scenarios. A key technique for sandboxing
is this:

   local danger = danger_function
   function safe (x)
     <dosomething>
     danger()
     <dosomething>
   end
   danger_function = nil

If you can call "safe" with a different environment, it may end up
calling "danger" in a non-safe way.

-- Roberto