lua-users home
lua-l archive

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


If dofile were to take extra parameters, it might be better to have it take
an environment:

    function dofile( name, env, ... )
        local f = loadfile( name )
        if env then
            setfenv( f, env )
        end
        return f( ... )
    end

Or go all out and specify it as:

    function dofile( name, dir, env, ... )
        local f = loadfile( name, dir )
        if env then
            setfenv( f, env )
        end
        return f( ... )
    end

Mark

on 1/16/05 3:49 PM, Luiz Henrique de Figueiredo at lhf@tecgraf.puc-rio.br
wrote:

>> 5.1 work4 has enhanced loadfile() so that it takes a second optional
>> parameter, namely the path to search for the file.
> [...] 
>> My question is whether dofile()  should have the take the same
>> optional second parameter?
> 
> Now that 5.1 allows access to unnamed varargs via "...", you may argue that
> it'd be better to map
> dofile(f,a1,a2,a3)
> into
> loadfile(f)(a1,a2,a3)
> 
> But perhaps it'd be simpler to just do as you suggest -- people needing
> to pass arguments to chunks could use
> loadfile(f,path)(a1,a2,a3)
> directly (and be clear about it).
> 
> --lhf