[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: require() relative to calling file
- From: Russell Haley <russ.haley@...>
- Date: Thu, 02 Feb 2017 23:34:17 -0800
Sorry for the top post.
But the question was what is the argument against the approach described. It always has seemed to me that Lua goes to great length to search relative paths and entirely negates to look in the application path for no reason whatsoever. It was one of the most confusing things when I first started looking at Lua.
Lua even interprets module names in require as directories and searches them for various patterns but doesn't try appending it to the application directory. I would love to know why because it seems so... missing?
Sent from my BlackBerry 10 smartphone on the Virgin Mobile network.
From: Sean Conner
Sent: Thursday, February 2, 2017 3:56 PM
To: Lua mailing list
Reply To: Lua mailing list
Subject: Re: require() relative to calling file
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.