The main problem is that package.path does not take into account the directory where the running script is located. Although Doug's solution works, it can become tedious if you need to keep adding
package.path = 'foobar_path/?.lua;'..package.path
for scripts that you plan to run from another working directory. What you need to do to make it easier is to create a module that will automatically add the script working directory to package.path when you need it. This module will be in one of the default locations listed in package.path so that it can be found.
-- moduleroot.lua local moduleroot = arg and arg[0] if moduleroot then local path = moduleroot:match [[^(.+[\/])[^\/]+$]] if path and
-- foo.lua require "moduleroot" require "bar"
This is actually a fairly common problem: Penlight includes a convenience tool to handle this: pl.app.require_here .
source share