Re: setfenv/getfenv
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: setfenv/getfenv
- From: Nevin Flanagan <Alestane@...>
- Date: 2010年1月12日 14:08:09 -0500
On Jan 12, 2010, at 1:39 PM, Daniel Silverstone wrote:
> On Tue, Jan 12, 2010 at 03:44:33PM -0200, Roberto Ierusalimschy wrote:
>> 'loadin' is like 'load'; it accepts a reader function as argument. So
>> there is no need to have the code as string at all.
>
> Gotcha, thanks.
It is relatively trivial to write a "loadfilewrappedin" function that incorporates this change:
function loadfilewrappedin(env, filename)
local source;
local function loader()
if source then
return source:read() or "\nend"
else
source = io.open(filename)
return "in ... do\n"
end
end
local function release(...)
source:close()
return ...
end
return release(loadin(env, loader, filename))
end
A "loadfilein" function that doesn't include the wrapper is even more trivial.