lua-users home
lua-l archive

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


It was thus said that the Great Andrew Starks once stated:
> On Mar 11, 2013, at 18:02, Michal Kottman <michal.kottman@gmail.com> wrote:
> >
> > The downside is that the database must be maintained manually and is
> > error-prone. A more robust way of building the database is on the way.
> >
> > Suggestions/improvements are welcome.
> >
> > [1] https://github.com/LuaDist/intellua
> >
> 
> This sounds cool, Mark.
> 
> Question... It seems like adding a package searcher to Lua would be
> the best place to make this works, as opposed to changing require's
> behavior. The searcher approach is even pointed out in PiL, I believe.
> Is there something I'm missing that makes this patch needed?

  I've thought about this, and it's a bit of a catch-22 going on.  You have

	package.loaders[1] = -- check package.preload[]
	package.loaders[2] = -- search package.path
	package.loaders[3] = -- search package.cpath
	package.loaders[4] = -- search package.cpath using another heuristic

  Now, let's say we have a loader "NETLOADER", which uses
LuaRocks/LuaDist/SomethingElseEntirely that will download and install
packages.  Here are the issues:

	package.loaders[1] = NETLOADER
	package.loaders[2] = -- check package.preload
	...

  If NETLOADER is in the first position, we duplicate the functionality of
the rest of the package.loaders array, unless we *always* want to check the
remote package servers everytime we start Lua.  If our network connection is
down, we'll have to wait for a timeout before checking locally.

	package.loaders[4] = -- search package.cpath using another heuristic
	package.loaders[5] = NETLOADER

  Here, we *know* we don't have it installed locally.  So we can go out and
install it.  Now ... what?  We want to restart require() in effect, so it
rescans package.path and package.cpath.  But there's no easy way of
restarting require().  I suppose we could call require() from within
NETLOADER, but only if we know that the package has installed correctly. 
If it falls through *again* to NETLOADER (for a given module X), then we
have to return failure, else we get into an infinite loop.  Note that this
too, could cause problems each time we start Lua and there's a network
problem (DNS issues, connectivity issues, etc.).

  I've come to the conclusion that while it might sound like a good idea
(either changing require() or adding a loader to package.loaders[]), in
practice, it probably won't be a good idea.

  -spc (Just my two zorkmids worth ... )