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 Griffin Rock once stated:
> >From Sean Conner:
> >   no file '/home/spc/.luarocks/share/lua/5.3/package:gopher/icon.lua'
> >   [etc]
> > This doesn't work because package.searchpath() isn't exactly what you want
> > (read it closely).
> 
> Hmm, odd. It looks like your Lua is replacing the "." with the
> directory separator, but it should be replacing the ":" instead.
> What release of Lua are you running?

  Lua 5.1, 5.2 or 5.3---take your pick (mostly 5.3 these days, but I still
use 5.1 at work.  5.2 wasn't a compelling enough version for me to use).

> > My mistake---there was a bug in the code [1] that didn't properly replace
> > the dots in the module name with directory separators.
> > It's all done in straight Lua.
> 
> Wait... do you mean you are monkey-patching package.searchpath
> (as opposed to 'require' or package.searchers)?
> Can I ask why, or would that be a spoiler?

  I added package.rpath to contain a list of directories to search for
resources based on a module name:

	package.rpath = "/usr/local/share/lua/5.3/?;..."

  I then added package.resources, an array of functions to load resources. 
There's only one function so far, a function that uses package.rpath to
locate a resource file.  I then created a function resource(), callable
like:

	f = resource("org.conman.app.gopherclient","gopher.icon")

  It returns an open file object of said resource, or throws an error with the
output you saw.

  There's no clean way to base a search path for resources from either
package.path or package.cpath.  Yes, you can split it on
package.config:sub(3,3) to get each entry, and you can locate the
replacement marker by looking for package.config:sub(5,5) but after that,
there's no real way to clean it up, so that's why the new path (which Soni
even alluded to).  I could have added a new entry to package.searchers, but
then I would have to rewrite require() to pass two pieces of information to
each searcher function and at this point, I didn't feel that was warranted
(being lazy---hey, I'm not the one asking for this feature) so I went with a
separate package.resources array instead.

  -spc (And what I have does with with Lua 5.1 or higher ... )