[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Unofficial FAQ Addition
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 6 Oct 2011 10:04:13 +0200
On Wed, Oct 5, 2011 at 7:36 PM, Rob Hoelz <rob@hoelz.ro> wrote:
> "How do I tell require to search relative to the current module?"
It's a good question, because it illuminates the central role of package.path.
The solution I use is to look at _G.arg[0] and work out the base path
from that; this seems to work fine and is the basis for
app.require_here() in Penlight: Then we modify package.(c)path
accordingly.
https://github.com/stevedonovan/Penlight/blob/master/lua/pl/app.lua
(If anybody _could_ see a potential problem with this method I would
be grateful)
I've seen people use debug information of the main script to find this
out, but I can't see any advantages of this. It would not work if
debug information had been stripped, for instance.
steve d.