lua-users home
lua-l archive

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


On Mon, Nov 14, 2011 at 11:47 AM, Oliver Mueller
<oliver.mueller@gmail.com> wrote:
> One script requires another like this:
> 1.script ("scripts/myscript.lua"):
> require('base') ...
> 2.script ("scripts/base.lua"): ...
> But when I call it from anywhere else, the require "base" is not found:

My findbin and lib [1,2] modules (based on analogous modules from
Perl) had that in mind:

  -- /qux/bar/baz.lua
  print(require 'findbin'.bin) --> prints directory of script (/qux/bar)
  require 'lib' (require 'findbin' '/../lib')
     -- adds a path relative to the directory of the current script to the
     -- package search paths (package.path & package.cpath).
  require 'foo'  -- loads from new search paths (/qux/lib/foo.lua)

[1] https://gist.github.com/1342319
[2] https://gist.github.com/1342365