[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require() relative to calling file
- From: Sean Conner <sean@...>
- Date: Thu, 2 Feb 2017 18:55:40 -0500
It was thus said that the Great email@example.com once stated:
> that topic has been discussed on several places in the we
> (stackoverflow, etc..) and while people came up with some solutions, I
> haven't really seen anybody making a case against it. So I'm
> wondering if that behaviour could be build into Lua ...
> What exactly do I mean?
> consider the following layout:
> a.lua has a require('b')
> Now if I do the following:
> # cd basedir/scripts
> # lua a.lua
> everything runs smoothly. But if I
> # cd basedir
> # lua scripts/a.lua
> I get an error that module 'b' can't be found because the searchpath
> is based of the current working directory.
> How to deal with it?
You could set LUA_PATH and LUA_CPATH before executing the program. You
could have a.lua do what you do below in C before the 'require "b"'
statement (the script name is in arg by the way). You could wrap the
invocation of a.lua in a shell script that changes to the proper directory
to run it.