[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: setfenv/getfenv
- From: Nevin Flanagan <Alestane@...>
- Date: Tue, 12 Jan 2010 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 function loader()
if source then
return source:read() or "\nend"
source = io.open(filename)
return "in ... do\n"
local function release(...)
return release(loadin(env, loader, filename))
A "loadfilein" function that doesn't include the wrapper is even more trivial.