lua-users home
lua-l archive

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


Roberto Ierusalimschy <roberto@inf.puc-rio.br> writes:

>> >  return load(io.lines(filename, 2^12), filename, 't', env)
>> 
>> It took me a minute to realize what `io.lines(filename, 2^12)`
>> meant. loadfile's signature is currently just `loadfile([filename])`,
>> why can't it be `loadfile([filename[, env]])` or `loadfile([filename[,
>> mode[, env]]])`?
>
> It certainly can. The point is whether it should ;) It increases both
> the implementation and the manual (but by minimal amounts).
>
> The change also breaks some code, like this one:
>
>   loadfile(string.gsub(filename, '%.', '/'))
>
> The result is a quite confusing error when running the chunk:

Deciding that an interface should explicitly ignore extra arguments
jusssst in case somebody decides to call it with extra results that
he'd like ignored is really, really, dodgy; I don't think it's a good
idea to go there.  After all, the same possibility exists with any
existing function that takes optional arguments...

Anyway, I think the current state with "loadfile" is confusing; it
should be a wrapper around "load" that takes care of the
open/close/buffering for you, but it's not really.  The changes to
make it do the right thing are trivial, and would make the Lua loading
functions both more useful and easier to understand (because they'd be
consistent).

BTW, is your io.lines example strictly correct?  I notice that it
doesn't work with luajit, because luajit's io.lines returns two
values, a function and a state, and apparently needs both to work...

-Miles

-- 
Justice, n. A commodity which in a more or less adulterated condition the
State sells to the citizen as a reward for his allegiance, taxes and personal
service.