[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require() relative to calling file
- From: Sean Conner <sean@...>
- Date: Sat, 4 Feb 2017 04:23:50 -0500
It was thus said that the Great Russell Haley once stated:
> On Fri, Feb 3, 2017 at 4:28 PM, Sean Conner <email@example.com> wrote:
> > So add it to your Lua application. That way, you don't have to wait for
> > the Lua team to add it.
> I have counter arguments but that's not the point. 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 simple fact is Lua searches a
> number of places for a variety of things to help the user out but
> negates this simple yet effective addition that won't break any other
> operating environment because you won't be using path separators if
> there is no filesystem. It provides huge functionality, doesn't break
> anything, provides continuity between that "other small operating
> system" that Lua supports, is 100% backwards compatible (because
> nobody could do it before) and is as simple as saving the results of a
> one time tokenization (is that the right word?). 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.
Again, add it to your Lua application if it's so important to you.
But okay, let's add the feature.
Where do you add the "application path"? Do you prepend it to
package.path? Or append it to package.path? And if you don't think it
makes a difference, it does:
GenericUnixPrompt> luawhich org.conman.parsers.email
See, I need to test my modules via LuaRocks, which is why I have this one
installed twice (once by me doing development, and once by LuaRocks to test
that method of installation---which reminds me, I probably need to remove
the LuaRocks version). By default, Lua will install the first one it finds
with the given name. You can get different results depending if a directory
is prepended or appended.
Will this problem come up often enough in practice? I don't know, but
having Lua do it automatically is *NOT* 100% safe (especially given the
number of modules having the same name, like "zlib"  or "syslog" ),
and even those wanting the feature will probably argue about where to add
Then there's the issue of where in Lua itself. Do you add it to liblua.a
(or lua.dll for those on Windows)? Or to the standalone Lua interpreter?
-spc (Not so simple now ... )
 A simple Google search for "lua zlib" revealed at least three Lua
modules called "zlib" with differing APIs.
 I know of at least four different Lua modules to syslog, three of
which have the same name.