lua-users home
lua-l archive

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


[Summary of thread: Some people would like Lua to add the directory
of the currently running main script automatically to the package path.
OP admits that other ways to achieve that effect exist but claims that
no good reason for Lua not to do so has been advanced. Several
posters have been stressing the other ways, but Russ keeps forcing
the issu back to "why not?" and is not impressed by the technical
arguments advanced so far.]

2017-02-04 8:48 GMT+02:00 Russell Haley <russ.haley@gmail.com>:

> The only reason I spoke up is because I ran into this myself when
> I was starting with Lua. The way it searches the current path and
> chooses the defaults to search is opaque to casual users.
...
> The best answer to "why not?"  is "because that's not the way we
> did it before". Fair enough, but I agree with the OP that it's a puzzling
> omission. And this is coming from a guy who likes to start counting
> from 1.

First, a little history.

In Lua 5.1, the current directory was the first one searched for
a package. Starting from Lua 5.2, it is the last. This was puzzling
too. I raised the issue on the list. The issue raised in this thread
surfaced in one of the contributions.

http://lua-users.org/lists/lua-l/2011-09/msg00607.html

where David Manura wrote:

> Note that the path "./?.lua" is relative to the current directory, but
> you'd probably rather search relative to the Lua executable (i.e. "!"
> style LUA_PATH in Windows / LuaDist setprogdir [3]) or relative to the
> current script [4-8].

Nobody at that stage clamoured for including the "relative to the
current script" feature.

The fact that the Lua team made the change means that we can
ask "why" instead of "why not". They never joined the discussion,
but the reason might be "because modules installed to /usr or /usr/local
were probably put there by the supervisor and are more likely to
be kosher".

This argument is equally applicable to the question whether paths
relative to the current script would be a good idea.