lua-users home
lua-l archive

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


On Tue, 2006-08-22 at 18:10 -0700, Mark Hamburg wrote:
> A way to tear off new copies of a function would definitely be useful. For
> example, I've got a class system that allows for arbitrary sequences of
> mixin classes. It would be great if when constructing a class out of mixins,
> I could tear off fresh copies of the functions and give them environments
> that would represent information such as their position in the mixin
> sequence.
> 
> Without support for creating multiple versions of the same function with
> different environments, one could almost replace setfenv with an extra
> parameter to load to set the environment on the newly loaded function.
> 

Really what is needed is the ability to create functions which aren't
closures. Because that's what's happening, right? All functions in Lua
are closures. Though, I suppose that doesn't solve the problem, either,
because in order to get the desired effect you'd need such behavior to
be the default, rather than selected.

I suppose a load method could do this. Something like loadfile() w/ a
switch that causes the defined functions to close the current
environment, or the functions to instantiate "environment-less"
functions which bind dynamically when called.

-- 
William Ahern <wahern@barracudanetworks.com>


--------------------------------------------------
This message was scanned for Spam, Spyware and Viruses
For more information, please visit:
http://www.barracudanetworks.com