lua-users home
lua-l archive

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


A.S. Bradbury wrote:
> 
>> But in order to address the "reuse"-issue again, with loadin() it would
>> only be easy to reuse the source and compile the function each time again.
> 
> I may be missing something, but does this solve the multiple reuse problem?
> 
> function multienv(funcstr)
>   return loadstring([[
>     return function(_G)
>       in _G do
>         return function()
>           ]]..funcstr..[[
>         end
>       end
>     end
>     ]]
>   )()
> end

No, that would operate on compiling source code for each environment.
That is already possible with the new loadin () function. What I was
looking for was reusing the function chunk without the need to compile
it again each time and without the need to copy it in extra strings
using string.dump ().

I still don't quite understand why a feature that wasn't broken in the
first place (setfenv/getfenv) is supposed to be removed. That these
functions are extremely powerful and can break a lot of things is
obvious. You would never put them inside a sandbox. But so are
getmetatable/setmetatable. You can also break other code using them.

The new "in ... do ... end" is a good addition for some uses setfenv()
was used for. loadin () can be used as a safer loadstring (), too. But I
still would like to keep the old functions.

- David