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 once stated:
> Hi,
> 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:
> -basedir
>  \
>   -scripts
>    \
>     -a.lua
>     -b.lua
> 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[0] by the way).  You could wrap the
invocation of a.lua in a shell script that changes to the proper directory
to run it.